diff --git a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java index c201178e..f4e4712a 100644 --- a/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java +++ b/gson/src/main/java/com/google/gson/DefaultTypeAdapters.java @@ -140,12 +140,12 @@ final class DefaultTypeAdapters { } static ParameterizedTypeHandlerMap> getDefaultSerializers() { - return getDefaultSerializers(false, LongSerializationPolicy.DEFAULT); + return DEFAULT_SERIALIZERS.copyOf(); } static ParameterizedTypeHandlerMap> getAllDefaultSerializers() { ParameterizedTypeHandlerMap> defaultSerializers = - getDefaultSerializers(false, LongSerializationPolicy.DEFAULT); + DEFAULT_SERIALIZERS.copyOf(); defaultSerializers.register(DEFAULT_HIERARCHY_SERIALIZERS); return defaultSerializers; } @@ -157,33 +157,6 @@ final class DefaultTypeAdapters { return defaultDeserializers; } - static ParameterizedTypeHandlerMap> getDefaultSerializers( - boolean serializeSpecialFloatingPointValues, LongSerializationPolicy longSerializationPolicy) { - ParameterizedTypeHandlerMap> serializers = - new ParameterizedTypeHandlerMap>(); - - // Double primitive - DefaultTypeAdapters.DoubleSerializer doubleSerializer = - new DefaultTypeAdapters.DoubleSerializer(serializeSpecialFloatingPointValues); - serializers.registerIfAbsent(Double.class, doubleSerializer); - serializers.registerIfAbsent(double.class, doubleSerializer); - - // Float primitive - DefaultTypeAdapters.FloatSerializer floatSerializer = - new DefaultTypeAdapters.FloatSerializer(serializeSpecialFloatingPointValues); - serializers.registerIfAbsent(Float.class, floatSerializer); - serializers.registerIfAbsent(float.class, floatSerializer); - - // Long primitive - DefaultTypeAdapters.LongSerializer longSerializer = - new DefaultTypeAdapters.LongSerializer(longSerializationPolicy); - serializers.registerIfAbsent(Long.class, longSerializer); - serializers.registerIfAbsent(long.class, longSerializer); - - serializers.registerIfAbsent(DEFAULT_SERIALIZERS); - return serializers; - } - static ParameterizedTypeHandlerMap> getDefaultDeserializers() { return DEFAULT_DESERIALIZERS; } @@ -461,61 +434,6 @@ final class DefaultTypeAdapters { } } - private static final class LongSerializer implements JsonSerializer { - private final LongSerializationPolicy longSerializationPolicy; - - private LongSerializer(LongSerializationPolicy longSerializationPolicy) { - this.longSerializationPolicy = longSerializationPolicy; - } - - public JsonElement serialize(Long src, Type typeOfSrc, JsonSerializationContext context) { - return longSerializationPolicy.serialize(src); - } - - @Override - public String toString() { - return LongSerializer.class.getSimpleName(); - } - } - - static final class FloatSerializer implements JsonSerializer { - private final boolean serializeSpecialFloatingPointValues; - - FloatSerializer(boolean serializeSpecialDoubleValues) { - this.serializeSpecialFloatingPointValues = serializeSpecialDoubleValues; - } - - public JsonElement serialize(Float src, Type typeOfSrc, JsonSerializationContext context) { - if (!serializeSpecialFloatingPointValues) { - if (Float.isNaN(src) || Float.isInfinite(src)) { - throw new IllegalArgumentException(src - + " is not a valid float value as per JSON specification. To override this" - + " behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method."); - } - } - return new JsonPrimitive(src); - } - } - - static final class DoubleSerializer implements JsonSerializer { - private final boolean serializeSpecialFloatingPointValues; - - DoubleSerializer(boolean serializeSpecialDoubleValues) { - this.serializeSpecialFloatingPointValues = serializeSpecialDoubleValues; - } - - public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { - if (!serializeSpecialFloatingPointValues) { - if (Double.isNaN(src) || Double.isInfinite(src)) { - throw new IllegalArgumentException(src - + " is not a valid double value as per JSON specification. To override this" - + " behavior, use GsonBuilder.serializeSpecialDoubleValues() method."); - } - } - return new JsonPrimitive(src); - } - } - private static final class CharacterTypeAdapter implements JsonSerializer, JsonDeserializer { public JsonElement serialize(Character src, Type typeOfSrc, JsonSerializationContext context) { diff --git a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java index c4188d49..a9ece86c 100644 --- a/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java +++ b/gson/src/test/java/com/google/gson/functional/PrimitiveTest.java @@ -34,9 +34,6 @@ import junit.framework.TestCase; * @author Joel Leitch */ public class PrimitiveTest extends TestCase { - private static final BigInteger MAX_INT_VALUE = new BigInteger("2147483647"); - private static final BigInteger MAX_LONG_VALUE = new BigInteger("9223372036854775807"); - private Gson gson; @Override