Example usage for com.google.gson LongSerializationPolicy DEFAULT

List of usage examples for com.google.gson LongSerializationPolicy DEFAULT

Introduction

In this page you can find the example usage for com.google.gson LongSerializationPolicy DEFAULT.

Prototype

LongSerializationPolicy DEFAULT

To view the source code for com.google.gson LongSerializationPolicy DEFAULT.

Click Source Link

Document

This is the "default" serialization policy that will output a long object as a JSON number.

Usage

From source file:com.gilecode.yagson.YaGson.java

License:Apache License

/**
 * Constructs a Gson object with the default configuration. The default configuration has the
 * following settings://from   w  ww . j a v a2 s . c  o  m
 * <ul>
 *   <li>By default, YaGson's detects all self-references and the duplicate objects in the whole references graph
 *   of the serialized object. All such objects except the first one are emitted as link-like references, see
 *   {@link ReferencesPolicy#DUPLICATE_OBJECTS}. Although this policy may be changed to the alternative ones by
 *   {@link YaGsonBuilder#setReferencesPolicy(ReferencesPolicy)}, it is not recommended in case of arbitrary objects,
 *   as the functionality of the deserialized objects may be broken.</li>
 *   <li>By default, the type information is emitted as {@literal @type/@value} wrappers when the actual types
 *   would be lost otherwise, i.e. when the known de-serialization type is less specific than the actual class
 *   of an object or its part being serialized. Use
 *   {@link YaGsonBuilder#setTypeInfoPolicy(TypeInfoPolicy)} to change it if necessary.</li>
 *   <li>The JSON generated by <code>toJson</code> methods is in compact representation. This
 *   means that all the unneeded white-space is removed. You can change this behavior with
 *   {@link GsonBuilder#setPrettyPrinting()}. </li>
 *   <li>The generated JSON omits all the fields that are null. Note that nulls in arrays are
 *   kept as is since an array is an ordered list. Moreover, if a field is not null, but its
 *   generated JSON is empty, the field is kept. You can configure Gson to serialize null values
 *   by setting {@link GsonBuilder#serializeNulls()}.</li>
 *   <li>The default Date format is same as {@link java.text.DateFormat#DEFAULT}. This format
 *   ignores the millisecond portion of the date during serialization. You can change
 *   this by invoking {@link GsonBuilder#setDateFormat(int)} or
 *   {@link GsonBuilder#setDateFormat(String)}. </li>
 *   <li>By default, Gson ignores the {@link com.google.gson.annotations.Expose} annotation.
 *   You can enable Gson to serialize/deserialize only those fields marked with this annotation
 *   through {@link GsonBuilder#excludeFieldsWithoutExposeAnnotation()}. </li>
 *   <li>By default, Gson ignores the {@link com.google.gson.annotations.Since} annotation. You
 *   can enable Gson to use this annotation through {@link GsonBuilder#setVersion(double)}.</li>
 *   <li>The default field naming policy for the output Json is same as in Java. So, a Java class
 *   field <code>versionNumber</code> will be output as <code>&quot;versionNumber&quot;</code> in
 *   Json. The same rules are applied for mapping incoming Json to the Java classes. You can
 *   change this policy through {@link GsonBuilder#setFieldNamingPolicy(FieldNamingPolicy)}.</li>
 *   <li>By default, YaGson excludes <code>static</code> fields from
 *   consideration for serialization and deserialization, but serializes most of <code>transient</code>
 *   fields.
 *   You can change this behavior through
 *   {@link GsonBuilder#excludeFieldsWithModifiers(int...)}.</li>
 * </ul>
 */
public YaGson() {
    super(Excluder.DEFAULT.forReferencesPolicy(References.defaultPolicy()), FieldNamingPolicy.IDENTITY,
            Collections.<Type, InstanceCreator<?>>emptyMap(), false, TypeInfoPolicy.defaultPolicy().isEnabled(),
            DEFAULT_JSON_NON_EXECUTABLE, !TypeInfoPolicy.defaultPolicy().isEnabled(), // disable htmlSafe if types are printed
            false, false, LongSerializationPolicy.DEFAULT, Collections.<TypeAdapterFactory>emptyList(),
            References.defaultPolicy(), TypeInfoPolicy.defaultPolicy());
}