diff --git a/gson/src/main/java/com/google/gson/JsonPrimitive.java b/gson/src/main/java/com/google/gson/JsonPrimitive.java index 029ab5b7..b12224bb 100644 --- a/gson/src/main/java/com/google/gson/JsonPrimitive.java +++ b/gson/src/main/java/com/google/gson/JsonPrimitive.java @@ -28,6 +28,10 @@ import java.math.BigInteger; */ public final class JsonPrimitive extends JsonElement { + private static final Class[] PRIMITIVE_TYPES = { int.class, long.class, short.class, + float.class, double.class, byte.class, boolean.class, char.class, Integer.class, Long.class, + Short.class, Float.class, Double.class, Byte.class, Boolean.class, Character.class }; + private Object value; /** @@ -95,7 +99,7 @@ public final class JsonPrimitive extends JsonElement { this.value = String.valueOf(c); } else { Preconditions.checkArgument(primitive instanceof Number - || ObjectNavigator.isPrimitiveOrString(primitive)); + || isPrimitiveOrString(primitive)); this.value = primitive; } } @@ -317,4 +321,18 @@ public final class JsonPrimitive extends JsonElement { } } } + + private static boolean isPrimitiveOrString(Object target) { + if (target instanceof String) { + return true; + } + + Class classOfPrimitive = target.getClass(); + for (Class standardPrimitive : PRIMITIVE_TYPES) { + if (standardPrimitive.isAssignableFrom(classOfPrimitive)) { + return true; + } + } + return false; + } } diff --git a/gson/src/main/java/com/google/gson/ObjectNavigator.java b/gson/src/main/java/com/google/gson/ObjectNavigator.java index 2f291641..fccafe8a 100644 --- a/gson/src/main/java/com/google/gson/ObjectNavigator.java +++ b/gson/src/main/java/com/google/gson/ObjectNavigator.java @@ -150,23 +150,4 @@ final class ObjectNavigator { } } } - - @SuppressWarnings("unchecked") - private static final Class[] PRIMITIVE_TYPES = { int.class, long.class, short.class, float.class, - double.class, byte.class, boolean.class, Integer.class, Long.class, Short.class, Float.class, - Double.class, Byte.class, Boolean.class }; - - @SuppressWarnings("unchecked") - static boolean isPrimitiveOrString(Object target) { - if (target instanceof String) { - return true; - } - Class classOfPrimitive = target.getClass(); - for (Class standardPrimitive : PRIMITIVE_TYPES) { - if (standardPrimitive.isAssignableFrom(classOfPrimitive)) { - return true; - } - } - return false; - } }