com.google.gson.internal.Excluder Java Examples

The following examples show how to use com.google.gson.internal.Excluder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnknownPropertiesTypeAdapterFactory.java    From sentry-android with MIT License 6 votes vote down vote up
private static Collection<String> getPropertyNames(
    final Class<?> clazz,
    final Excluder excluder,
    final FieldNamingStrategy fieldNamingStrategy) {
  final Collection<String> propertyNames = new ArrayList<>();
  // Class fields are declared per class so we have to traverse the whole hierarchy
  for (Class<?> i = clazz;
      i.getSuperclass() != null && i != Object.class;
      i = i.getSuperclass()) {
    for (final Field declaredField : i.getDeclaredFields()) {
      // If the class field is not excluded
      if (!excluder.excludeField(declaredField, false)) {
        // We can translate the field name to its property name counter-part
        final String propertyName = fieldNamingStrategy.translateName(declaredField);
        propertyNames.add(propertyName);
      }
    }
  }
  return propertyNames;
}
 
Example #2
Source File: UnknownPropertiesTypeAdapterFactory.java    From sentry-android with MIT License 6 votes vote down vote up
@Override
public <T> TypeAdapter<T> create(final Gson gson, final TypeToken<T> typeToken) {
  // Check if we can deal with the given type
  if (!IUnknownPropertiesConsumer.class.isAssignableFrom(typeToken.getRawType())) {
    return null;
  }
  // If we can, we should get the backing class to fetch its fields from
  @SuppressWarnings("unchecked")
  final Class<IUnknownPropertiesConsumer> rawType =
      (Class<IUnknownPropertiesConsumer>) typeToken.getRawType();
  @SuppressWarnings("unchecked")
  final TypeAdapter<IUnknownPropertiesConsumer> delegateTypeAdapter =
      (TypeAdapter<IUnknownPropertiesConsumer>) gson.getDelegateAdapter(this, typeToken);
  // Excluder is necessary to check if the field can be processed
  // Basically it's not required, but it makes the check more complete
  final Excluder excluder = gson.excluder();
  // This is crucial to map fields and JSON object properties since Gson supports name remapping
  final FieldNamingStrategy fieldNamingStrategy = gson.fieldNamingStrategy();
  final TypeAdapter<IUnknownPropertiesConsumer> unknownPropertiesTypeAdapter =
      UnknownPropertiesTypeAdapter.create(
          rawType, delegateTypeAdapter, excluder, fieldNamingStrategy);
  @SuppressWarnings("unchecked")
  final TypeAdapter<T> castTypeAdapter = (TypeAdapter<T>) unknownPropertiesTypeAdapter;
  return castTypeAdapter;
}
 
Example #3
Source File: UnknownPropertiesTypeAdapterFactory.java    From sentry-android with MIT License 5 votes vote down vote up
private static <T extends IUnknownPropertiesConsumer> TypeAdapter<T> create(
    final Class<? super T> clazz,
    final TypeAdapter<T> typeAdapter,
    final Excluder excluder,
    final FieldNamingStrategy fieldNamingStrategy) {
  final Collection<String> propertyNames =
      getPropertyNames(clazz, excluder, fieldNamingStrategy);
  return new UnknownPropertiesTypeAdapter<>(typeAdapter, propertyNames);
}
 
Example #4
Source File: GsonJsonEngine.java    From lastaflute with Apache License 2.0 5 votes vote down vote up
protected LaReflectiveTypeAdapterFactory createReflectiveTypeAdapterFactory(Gson newGson, Object factory) {
    final ConstructorConstructor constructorConstructor = getConstructorConstructor(factory);
    final JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory = getJsonAdapterFactory(factory);
    final FieldNamingStrategy fieldNamingStrategy = newGson.fieldNamingStrategy();
    final Excluder excluder = newGson.excluder();
    return new LaReflectiveTypeAdapterFactory(constructorConstructor, fieldNamingStrategy, excluder, jsonAdapterFactory);
}
 
Example #5
Source File: LaReflectiveTypeAdapterFactory.java    From lastaflute with Apache License 2.0 5 votes vote down vote up
public LaReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy,
        Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) {
    this.constructorConstructor = constructorConstructor;
    this.fieldNamingPolicy = fieldNamingPolicy;
    this.excluder = excluder;
    this.jsonAdapterFactory = jsonAdapterFactory;
}
 
Example #6
Source File: GsonBuilder.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public GsonBuilder()
{
    a = Excluder.DEFAULT;
    b = LongSerializationPolicy.DEFAULT;
    c = FieldNamingPolicy.IDENTITY;
    i = 2;
    j = 2;
    m = true;
}
 
Example #7
Source File: ReflectiveTypeAdapterFactory.java    From gson with Apache License 2.0 5 votes vote down vote up
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
    FieldNamingStrategy fieldNamingPolicy, Excluder excluder,
    JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) {
  this.constructorConstructor = constructorConstructor;
  this.fieldNamingPolicy = fieldNamingPolicy;
  this.excluder = excluder;
  this.jsonAdapterFactory = jsonAdapterFactory;
}
 
Example #8
Source File: ReflectiveTypeAdapterFactory.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
static boolean excludeField(Field f, boolean serialize, Excluder excluder) {
  return !excluder.excludeClass(f.getType(), serialize) && !excluder.excludeField(f, serialize);
}
 
Example #9
Source File: ReflectiveTypeAdapterFactory.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
    FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
  this.constructorConstructor = constructorConstructor;
  this.fieldNamingPolicy = fieldNamingPolicy;
  this.excluder = excluder;
}
 
Example #10
Source File: Gson.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
Gson(final Excluder excluder, final FieldNamingStrategy fieldNamingPolicy,
    final Map<Type, InstanceCreator<?>> instanceCreators, boolean serializeNulls,
    boolean complexMapKeySerialization, boolean generateNonExecutableGson, boolean htmlSafe,
    boolean prettyPrinting, boolean serializeSpecialFloatingPointValues,
    LongSerializationPolicy longSerializationPolicy,
    List<TypeAdapterFactory> typeAdapterFactories) {
  this.constructorConstructor = new ConstructorConstructor(instanceCreators);
  this.serializeNulls = serializeNulls;
  this.generateNonExecutableJson = generateNonExecutableGson;
  this.htmlSafe = htmlSafe;
  this.prettyPrinting = prettyPrinting;

  List<TypeAdapterFactory> factories = new ArrayList<TypeAdapterFactory>();

  // built-in type adapters that cannot be overridden
  factories.add(TypeAdapters.JSON_ELEMENT_FACTORY);
  factories.add(ObjectTypeAdapter.FACTORY);

  // the excluder must precede all adapters that handle user-defined types
  factories.add(excluder);

  // user's type adapters
  factories.addAll(typeAdapterFactories);

  // type adapters for basic platform types
  factories.add(TypeAdapters.STRING_FACTORY);
  factories.add(TypeAdapters.INTEGER_FACTORY);
  factories.add(TypeAdapters.BOOLEAN_FACTORY);
  factories.add(TypeAdapters.BYTE_FACTORY);
  factories.add(TypeAdapters.SHORT_FACTORY);
  factories.add(TypeAdapters.newFactory(long.class, Long.class,
          longAdapter(longSerializationPolicy)));
  factories.add(TypeAdapters.newFactory(double.class, Double.class,
          doubleAdapter(serializeSpecialFloatingPointValues)));
  factories.add(TypeAdapters.newFactory(float.class, Float.class,
          floatAdapter(serializeSpecialFloatingPointValues)));
  factories.add(TypeAdapters.NUMBER_FACTORY);
  factories.add(TypeAdapters.CHARACTER_FACTORY);
  factories.add(TypeAdapters.STRING_BUILDER_FACTORY);
  factories.add(TypeAdapters.STRING_BUFFER_FACTORY);
  factories.add(TypeAdapters.newFactory(BigDecimal.class, TypeAdapters.BIG_DECIMAL));
  factories.add(TypeAdapters.newFactory(BigInteger.class, TypeAdapters.BIG_INTEGER));
  factories.add(TypeAdapters.URL_FACTORY);
  factories.add(TypeAdapters.URI_FACTORY);
  factories.add(TypeAdapters.UUID_FACTORY);
  factories.add(TypeAdapters.LOCALE_FACTORY);
  factories.add(TypeAdapters.INET_ADDRESS_FACTORY);
  factories.add(TypeAdapters.BIT_SET_FACTORY);
  factories.add(DateTypeAdapter.FACTORY);
  factories.add(TypeAdapters.CALENDAR_FACTORY);
  factories.add(TimeTypeAdapter.FACTORY);
  factories.add(SqlDateTypeAdapter.FACTORY);
  factories.add(TypeAdapters.TIMESTAMP_FACTORY);
  factories.add(ArrayTypeAdapter.FACTORY);
  factories.add(TypeAdapters.CLASS_FACTORY);

  // type adapters for composite and user-defined types
  factories.add(new CollectionTypeAdapterFactory(constructorConstructor));
  factories.add(new MapTypeAdapterFactory(constructorConstructor, complexMapKeySerialization));
  factories.add(new JsonAdapterAnnotationTypeAdapterFactory(constructorConstructor));
  factories.add(TypeAdapters.ENUM_FACTORY);
  factories.add(new ReflectiveTypeAdapterFactory(
      constructorConstructor, fieldNamingPolicy, excluder));

  this.factories = Collections.unmodifiableList(factories);
}
 
Example #11
Source File: VersionExclusionStrategyTest.java    From gson with Apache License 2.0 4 votes vote down vote up
public void testClassAndFieldAreAheadInVersion() throws Exception {
  Excluder excluder = Excluder.DEFAULT.withVersion(VERSION - 1);
  assertTrue(excluder.excludeClass(MockObject.class, true));
  assertTrue(excluder.excludeField(MockObject.class.getField("someField"), true));
}
 
Example #12
Source File: VersionExclusionStrategyTest.java    From gson with Apache License 2.0 4 votes vote down vote up
public void testClassAndFieldAreBehindInVersion() throws Exception {
  Excluder excluder = Excluder.DEFAULT.withVersion(VERSION + 1);
  assertFalse(excluder.excludeClass(MockObject.class, true));
  assertFalse(excluder.excludeField(MockObject.class.getField("someField"), true));
}
 
Example #13
Source File: VersionExclusionStrategyTest.java    From gson with Apache License 2.0 4 votes vote down vote up
public void testClassAndFieldAreAtSameVersion() throws Exception {
  Excluder excluder = Excluder.DEFAULT.withVersion(VERSION);
  assertFalse(excluder.excludeClass(MockObject.class, true));
  assertFalse(excluder.excludeField(MockObject.class.getField("someField"), true));
}
 
Example #14
Source File: ReflectiveTypeAdapterFactory.java    From gson with Apache License 2.0 4 votes vote down vote up
static boolean excludeField(Field f, boolean serialize, Excluder excluder) {
  return !excluder.excludeClass(f.getType(), serialize) && !excluder.excludeField(f, serialize);
}
 
Example #15
Source File: Gson.java    From gson with Apache License 2.0 4 votes vote down vote up
public Excluder excluder() {
  return excluder;
}
 
Example #16
Source File: Gson.java    From gson with Apache License 2.0 4 votes vote down vote up
Gson(Excluder excluder, FieldNamingStrategy fieldNamingStrategy,
    Map<Type, InstanceCreator<?>> instanceCreators, boolean serializeNulls,
    boolean complexMapKeySerialization, boolean generateNonExecutableGson, boolean htmlSafe,
    boolean prettyPrinting, boolean lenient, boolean serializeSpecialFloatingPointValues,
    LongSerializationPolicy longSerializationPolicy, String datePattern, int dateStyle,
    int timeStyle, List<TypeAdapterFactory> builderFactories,
    List<TypeAdapterFactory> builderHierarchyFactories,
    List<TypeAdapterFactory> factoriesToBeAdded) {
  this.excluder = excluder;
  this.fieldNamingStrategy = fieldNamingStrategy;
  this.instanceCreators = instanceCreators;
  this.constructorConstructor = new ConstructorConstructor(instanceCreators);
  this.serializeNulls = serializeNulls;
  this.complexMapKeySerialization = complexMapKeySerialization;
  this.generateNonExecutableJson = generateNonExecutableGson;
  this.htmlSafe = htmlSafe;
  this.prettyPrinting = prettyPrinting;
  this.lenient = lenient;
  this.serializeSpecialFloatingPointValues = serializeSpecialFloatingPointValues;
  this.longSerializationPolicy = longSerializationPolicy;
  this.datePattern = datePattern;
  this.dateStyle = dateStyle;
  this.timeStyle = timeStyle;
  this.builderFactories = builderFactories;
  this.builderHierarchyFactories = builderHierarchyFactories;

  List<TypeAdapterFactory> factories = new ArrayList<TypeAdapterFactory>();

  // built-in type adapters that cannot be overridden
  factories.add(TypeAdapters.JSON_ELEMENT_FACTORY);
  factories.add(ObjectTypeAdapter.FACTORY);

  // the excluder must precede all adapters that handle user-defined types
  factories.add(excluder);

  // users' type adapters
  factories.addAll(factoriesToBeAdded);

  // type adapters for basic platform types
  factories.add(TypeAdapters.STRING_FACTORY);
  factories.add(TypeAdapters.INTEGER_FACTORY);
  factories.add(TypeAdapters.BOOLEAN_FACTORY);
  factories.add(TypeAdapters.BYTE_FACTORY);
  factories.add(TypeAdapters.SHORT_FACTORY);
  TypeAdapter<Number> longAdapter = longAdapter(longSerializationPolicy);
  factories.add(TypeAdapters.newFactory(long.class, Long.class, longAdapter));
  factories.add(TypeAdapters.newFactory(double.class, Double.class,
          doubleAdapter(serializeSpecialFloatingPointValues)));
  factories.add(TypeAdapters.newFactory(float.class, Float.class,
          floatAdapter(serializeSpecialFloatingPointValues)));
  factories.add(TypeAdapters.NUMBER_FACTORY);
  factories.add(TypeAdapters.ATOMIC_INTEGER_FACTORY);
  factories.add(TypeAdapters.ATOMIC_BOOLEAN_FACTORY);
  factories.add(TypeAdapters.newFactory(AtomicLong.class, atomicLongAdapter(longAdapter)));
  factories.add(TypeAdapters.newFactory(AtomicLongArray.class, atomicLongArrayAdapter(longAdapter)));
  factories.add(TypeAdapters.ATOMIC_INTEGER_ARRAY_FACTORY);
  factories.add(TypeAdapters.CHARACTER_FACTORY);
  factories.add(TypeAdapters.STRING_BUILDER_FACTORY);
  factories.add(TypeAdapters.STRING_BUFFER_FACTORY);
  factories.add(TypeAdapters.newFactory(BigDecimal.class, TypeAdapters.BIG_DECIMAL));
  factories.add(TypeAdapters.newFactory(BigInteger.class, TypeAdapters.BIG_INTEGER));
  factories.add(TypeAdapters.URL_FACTORY);
  factories.add(TypeAdapters.URI_FACTORY);
  factories.add(TypeAdapters.UUID_FACTORY);
  factories.add(TypeAdapters.CURRENCY_FACTORY);
  factories.add(TypeAdapters.LOCALE_FACTORY);
  factories.add(TypeAdapters.INET_ADDRESS_FACTORY);
  factories.add(TypeAdapters.BIT_SET_FACTORY);
  factories.add(DateTypeAdapter.FACTORY);
  factories.add(TypeAdapters.CALENDAR_FACTORY);
  factories.add(TimeTypeAdapter.FACTORY);
  factories.add(SqlDateTypeAdapter.FACTORY);
  factories.add(TypeAdapters.TIMESTAMP_FACTORY);
  factories.add(ArrayTypeAdapter.FACTORY);
  factories.add(TypeAdapters.CLASS_FACTORY);

  // type adapters for composite and user-defined types
  factories.add(new CollectionTypeAdapterFactory(constructorConstructor));
  factories.add(new MapTypeAdapterFactory(constructorConstructor, complexMapKeySerialization));
  this.jsonAdapterFactory = new JsonAdapterAnnotationTypeAdapterFactory(constructorConstructor);
  factories.add(jsonAdapterFactory);
  factories.add(TypeAdapters.ENUM_FACTORY);
  factories.add(new ReflectiveTypeAdapterFactory(
      constructorConstructor, fieldNamingStrategy, excluder, jsonAdapterFactory));

  this.factories = Collections.unmodifiableList(factories);
}
 
Example #17
Source File: ReflectiveTypeAdapterFactory.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorconstructor, FieldNamingStrategy fieldnamingstrategy, Excluder excluder)
{
    a = constructorconstructor;
    b = fieldnamingstrategy;
    c = excluder;
}
 
Example #18
Source File: Gson.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
Gson(Excluder excluder, FieldNamingStrategy fieldnamingstrategy, Map map, boolean flag, boolean flag1, boolean flag2, boolean flag3, 
        boolean flag4, boolean flag5, LongSerializationPolicy longserializationpolicy, List list)
{
    e = new ThreadLocal();
    f = Collections.synchronizedMap(new HashMap());
    b = new g(this);
    c = new h(this);
    h = new ConstructorConstructor(map);
    i = flag;
    k = flag2;
    j = flag3;
    l = flag4;
    ArrayList arraylist = new ArrayList();
    arraylist.add(TypeAdapters.JSON_ELEMENT_FACTORY);
    arraylist.add(ObjectTypeAdapter.FACTORY);
    arraylist.add(excluder);
    arraylist.addAll(list);
    arraylist.add(TypeAdapters.STRING_FACTORY);
    arraylist.add(TypeAdapters.INTEGER_FACTORY);
    arraylist.add(TypeAdapters.BOOLEAN_FACTORY);
    arraylist.add(TypeAdapters.BYTE_FACTORY);
    arraylist.add(TypeAdapters.SHORT_FACTORY);
    arraylist.add(TypeAdapters.newFactory(Long.TYPE, java/lang/Long, a(longserializationpolicy)));
    arraylist.add(TypeAdapters.newFactory(Double.TYPE, java/lang/Double, a(flag5)));
    arraylist.add(TypeAdapters.newFactory(Float.TYPE, java/lang/Float, b(flag5)));
    arraylist.add(TypeAdapters.NUMBER_FACTORY);
    arraylist.add(TypeAdapters.CHARACTER_FACTORY);
    arraylist.add(TypeAdapters.STRING_BUILDER_FACTORY);
    arraylist.add(TypeAdapters.STRING_BUFFER_FACTORY);
    arraylist.add(TypeAdapters.newFactory(java/math/BigDecimal, TypeAdapters.BIG_DECIMAL));
    arraylist.add(TypeAdapters.newFactory(java/math/BigInteger, TypeAdapters.BIG_INTEGER));
    arraylist.add(TypeAdapters.URL_FACTORY);
    arraylist.add(TypeAdapters.URI_FACTORY);
    arraylist.add(TypeAdapters.UUID_FACTORY);
    arraylist.add(TypeAdapters.LOCALE_FACTORY);
    arraylist.add(TypeAdapters.INET_ADDRESS_FACTORY);
    arraylist.add(TypeAdapters.BIT_SET_FACTORY);
    arraylist.add(DateTypeAdapter.FACTORY);
    arraylist.add(TypeAdapters.CALENDAR_FACTORY);
    arraylist.add(TimeTypeAdapter.FACTORY);
    arraylist.add(SqlDateTypeAdapter.FACTORY);
    arraylist.add(TypeAdapters.TIMESTAMP_FACTORY);
    arraylist.add(ArrayTypeAdapter.FACTORY);
    arraylist.add(TypeAdapters.ENUM_FACTORY);
    arraylist.add(TypeAdapters.CLASS_FACTORY);
    arraylist.add(new CollectionTypeAdapterFactory(h));
    arraylist.add(new MapTypeAdapterFactory(h, flag1));
    arraylist.add(new ReflectiveTypeAdapterFactory(h, fieldnamingstrategy, excluder));
    g = Collections.unmodifiableList(arraylist);
}
 
Example #19
Source File: Gson.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public Gson()
{
    this(Excluder.DEFAULT, ((FieldNamingStrategy) (FieldNamingPolicy.IDENTITY)), Collections.emptyMap(), false, false, false, true, false, false, LongSerializationPolicy.DEFAULT, Collections.emptyList());
}
 
Example #20
Source File: LaReflectiveTypeAdapterFactory.java    From lastaflute with Apache License 2.0 4 votes vote down vote up
protected static boolean excludeField(Field f, boolean serialize, Excluder excluder) {
    return !excluder.excludeClass(f.getType(), serialize) && !excluder.excludeField(f, serialize);
}
 
Example #21
Source File: ReflectiveTypeAdapterFactory.java    From letv with Apache License 2.0 4 votes vote down vote up
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
    this.constructorConstructor = constructorConstructor;
    this.fieldNamingPolicy = fieldNamingPolicy;
    this.excluder = excluder;
}
 
Example #22
Source File: Gson.java    From letv with Apache License 2.0 4 votes vote down vote up
public Gson() {
    this(Excluder.DEFAULT, FieldNamingPolicy.IDENTITY, Collections.emptyMap(), false, false, false, true, false, false, LongSerializationPolicy.DEFAULT, Collections.emptyList());
}
 
Example #23
Source File: Gson.java    From gson with Apache License 2.0 3 votes vote down vote up
/**
 * Constructs a Gson object with default configuration. The default configuration has the
 * following settings:
 * <ul>
 *   <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>Gson provides default serialization and deserialization for Enums, {@link Map},
 *   {@link java.net.URL}, {@link java.net.URI}, {@link java.util.Locale}, {@link java.util.Date},
 *   {@link java.math.BigDecimal}, and {@link java.math.BigInteger} classes. If you would prefer
 *   to change the default representation, you can do so by registering a type adapter through
 *   {@link GsonBuilder#registerTypeAdapter(Type, Object)}. </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, Gson excludes <code>transient</code> or <code>static</code> fields from
 *   consideration for serialization and deserialization. You can change this behavior through
 *   {@link GsonBuilder#excludeFieldsWithModifiers(int...)}.</li>
 * </ul>
 */
public Gson() {
  this(Excluder.DEFAULT, FieldNamingPolicy.IDENTITY,
      Collections.<Type, InstanceCreator<?>>emptyMap(), DEFAULT_SERIALIZE_NULLS,
      DEFAULT_COMPLEX_MAP_KEYS, DEFAULT_JSON_NON_EXECUTABLE, DEFAULT_ESCAPE_HTML,
      DEFAULT_PRETTY_PRINT, DEFAULT_LENIENT, DEFAULT_SPECIALIZE_FLOAT_VALUES,
      LongSerializationPolicy.DEFAULT, null, DateFormat.DEFAULT, DateFormat.DEFAULT,
      Collections.<TypeAdapterFactory>emptyList(), Collections.<TypeAdapterFactory>emptyList(),
      Collections.<TypeAdapterFactory>emptyList());
}
 
Example #24
Source File: Gson.java    From framework with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Constructs a Gson object with default configuration. The default configuration has the
 * following settings:
 * <ul>
 *   <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>Gson provides default serialization and deserialization for Enums, {@link Map},
 *   {@link java.net.URL}, {@link java.net.URI}, {@link java.util.Locale}, {@link java.util.Date},
 *   {@link BigDecimal}, and {@link BigInteger} classes. If you would prefer
 *   to change the default representation, you can do so by registering a type adapter through
 *   {@link GsonBuilder#registerTypeAdapter(Type, Object)}. </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, Gson excludes <code>transient</code> or <code>static</code> fields from
 *   consideration for serialization and deserialization. You can change this behavior through
 *   {@link GsonBuilder#excludeFieldsWithModifiers(int...)}.</li>
 * </ul>
 */
public Gson() {
  this(Excluder.DEFAULT, FieldNamingPolicy.IDENTITY,
      Collections.<Type, InstanceCreator<?>>emptyMap(), false, false, DEFAULT_JSON_NON_EXECUTABLE,
      true, false, false, LongSerializationPolicy.DEFAULT,
      Collections.<TypeAdapterFactory>emptyList());
}