Merge branch 'rharter-rh/config-props'
* rharter-rh/config-props: Adds getters for config fields.
This commit is contained in:
commit
d5c090835f
|
@ -127,6 +127,8 @@ public final class Gson {
|
||||||
private final List<TypeAdapterFactory> factories;
|
private final List<TypeAdapterFactory> factories;
|
||||||
private final ConstructorConstructor constructorConstructor;
|
private final ConstructorConstructor constructorConstructor;
|
||||||
|
|
||||||
|
private final Excluder excluder;
|
||||||
|
private final FieldNamingStrategy fieldNamingStrategy;
|
||||||
private final boolean serializeNulls;
|
private final boolean serializeNulls;
|
||||||
private final boolean htmlSafe;
|
private final boolean htmlSafe;
|
||||||
private final boolean generateNonExecutableJson;
|
private final boolean generateNonExecutableJson;
|
||||||
|
@ -175,13 +177,15 @@ public final class Gson {
|
||||||
LongSerializationPolicy.DEFAULT, Collections.<TypeAdapterFactory>emptyList());
|
LongSerializationPolicy.DEFAULT, Collections.<TypeAdapterFactory>emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Gson(final Excluder excluder, final FieldNamingStrategy fieldNamingPolicy,
|
Gson(final Excluder excluder, final FieldNamingStrategy fieldNamingStrategy,
|
||||||
final Map<Type, InstanceCreator<?>> instanceCreators, boolean serializeNulls,
|
final Map<Type, InstanceCreator<?>> instanceCreators, boolean serializeNulls,
|
||||||
boolean complexMapKeySerialization, boolean generateNonExecutableGson, boolean htmlSafe,
|
boolean complexMapKeySerialization, boolean generateNonExecutableGson, boolean htmlSafe,
|
||||||
boolean prettyPrinting, boolean lenient, boolean serializeSpecialFloatingPointValues,
|
boolean prettyPrinting, boolean lenient, boolean serializeSpecialFloatingPointValues,
|
||||||
LongSerializationPolicy longSerializationPolicy,
|
LongSerializationPolicy longSerializationPolicy,
|
||||||
List<TypeAdapterFactory> typeAdapterFactories) {
|
List<TypeAdapterFactory> typeAdapterFactories) {
|
||||||
this.constructorConstructor = new ConstructorConstructor(instanceCreators);
|
this.constructorConstructor = new ConstructorConstructor(instanceCreators);
|
||||||
|
this.excluder = excluder;
|
||||||
|
this.fieldNamingStrategy = fieldNamingStrategy;
|
||||||
this.serializeNulls = serializeNulls;
|
this.serializeNulls = serializeNulls;
|
||||||
this.generateNonExecutableJson = generateNonExecutableGson;
|
this.generateNonExecutableJson = generateNonExecutableGson;
|
||||||
this.htmlSafe = htmlSafe;
|
this.htmlSafe = htmlSafe;
|
||||||
|
@ -244,11 +248,27 @@ public final class Gson {
|
||||||
factories.add(new JsonAdapterAnnotationTypeAdapterFactory(constructorConstructor));
|
factories.add(new JsonAdapterAnnotationTypeAdapterFactory(constructorConstructor));
|
||||||
factories.add(TypeAdapters.ENUM_FACTORY);
|
factories.add(TypeAdapters.ENUM_FACTORY);
|
||||||
factories.add(new ReflectiveTypeAdapterFactory(
|
factories.add(new ReflectiveTypeAdapterFactory(
|
||||||
constructorConstructor, fieldNamingPolicy, excluder));
|
constructorConstructor, fieldNamingStrategy, excluder));
|
||||||
|
|
||||||
this.factories = Collections.unmodifiableList(factories);
|
this.factories = Collections.unmodifiableList(factories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Excluder excluder() {
|
||||||
|
return excluder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldNamingStrategy fieldNamingStrategy() {
|
||||||
|
return fieldNamingStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean serializeNulls() {
|
||||||
|
return serializeNulls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean htmlSafe() {
|
||||||
|
return htmlSafe;
|
||||||
|
}
|
||||||
|
|
||||||
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
|
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) {
|
||||||
if (serializeSpecialFloatingPointValues) {
|
if (serializeSpecialFloatingPointValues) {
|
||||||
return TypeAdapters.DOUBLE;
|
return TypeAdapters.DOUBLE;
|
||||||
|
|
54
gson/src/test/java/com/google/gson/GsonTest.java
Normal file
54
gson/src/test/java/com/google/gson/GsonTest.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The Gson Authors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.gson;
|
||||||
|
|
||||||
|
import com.google.gson.internal.Excluder;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for {@link Gson}.
|
||||||
|
*
|
||||||
|
* @author Ryan Harter
|
||||||
|
*/
|
||||||
|
public final class GsonTest extends TestCase {
|
||||||
|
|
||||||
|
private static final Excluder CUSTOM_EXCLUDER = Excluder.DEFAULT
|
||||||
|
.excludeFieldsWithoutExposeAnnotation()
|
||||||
|
.disableInnerClassSerialization();
|
||||||
|
|
||||||
|
private static final FieldNamingStrategy CUSTOM_FIELD_NAMING_STRATEGY = new FieldNamingStrategy() {
|
||||||
|
@Override public String translateName(Field f) {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public void testOverridesDefaultExcluder() {
|
||||||
|
Gson gson = new Gson(CUSTOM_EXCLUDER, CUSTOM_FIELD_NAMING_STRATEGY,
|
||||||
|
new HashMap<Type, InstanceCreator<?>>(), true, false, true, false,
|
||||||
|
true, true, false, LongSerializationPolicy.DEFAULT,
|
||||||
|
new ArrayList<TypeAdapterFactory>());
|
||||||
|
|
||||||
|
assertEquals(CUSTOM_EXCLUDER, gson.excluder());
|
||||||
|
assertEquals(CUSTOM_FIELD_NAMING_STRATEGY, gson.fieldNamingStrategy());
|
||||||
|
assertEquals(true, gson.serializeNulls());
|
||||||
|
assertEquals(false, gson.htmlSafe());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user