Warning fixes.
This commit is contained in:
parent
f4098b5cf7
commit
f6a332971f
|
@ -62,7 +62,7 @@ final class DefaultTypeAdapters {
|
||||||
private static final DefaultTimestampDeserializer TIMESTAMP_DESERIALIZER =
|
private static final DefaultTimestampDeserializer TIMESTAMP_DESERIALIZER =
|
||||||
new DefaultTimestampDeserializer();
|
new DefaultTimestampDeserializer();
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
private static final EnumTypeAdapter ENUM_TYPE_ADAPTER = new EnumTypeAdapter();
|
private static final EnumTypeAdapter ENUM_TYPE_ADAPTER = new EnumTypeAdapter();
|
||||||
private static final UrlTypeAdapter URL_TYPE_ADAPTER = new UrlTypeAdapter();
|
private static final UrlTypeAdapter URL_TYPE_ADAPTER = new UrlTypeAdapter();
|
||||||
private static final UriTypeAdapter URI_TYPE_ADAPTER = new UriTypeAdapter();
|
private static final UriTypeAdapter URI_TYPE_ADAPTER = new UriTypeAdapter();
|
||||||
|
@ -87,7 +87,7 @@ final class DefaultTypeAdapters {
|
||||||
private static final PropertiesCreator PROPERTIES_CREATOR = new PropertiesCreator();
|
private static final PropertiesCreator PROPERTIES_CREATOR = new PropertiesCreator();
|
||||||
private static final TreeSetCreator TREE_SET_CREATOR = new TreeSetCreator();
|
private static final TreeSetCreator TREE_SET_CREATOR = new TreeSetCreator();
|
||||||
private static final HashSetCreator HASH_SET_CREATOR = new HashSetCreator();
|
private static final HashSetCreator HASH_SET_CREATOR = new HashSetCreator();
|
||||||
private static final GregorianCalendarTypeAdapter GREGORIAN_CALENDAR_TYPE_ADAPTER =
|
private static final GregorianCalendarTypeAdapter GREGORIAN_CALENDAR_TYPE_ADAPTER =
|
||||||
new GregorianCalendarTypeAdapter();
|
new GregorianCalendarTypeAdapter();
|
||||||
|
|
||||||
// The constants DEFAULT_SERIALIZERS, DEFAULT_DESERIALIZERS, and DEFAULT_INSTANCE_CREATORS
|
// The constants DEFAULT_SERIALIZERS, DEFAULT_DESERIALIZERS, and DEFAULT_INSTANCE_CREATORS
|
||||||
|
@ -119,7 +119,7 @@ final class DefaultTypeAdapters {
|
||||||
map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER);
|
map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER);
|
||||||
map.register(BigDecimal.class, BIG_DECIMAL_TYPE_ADAPTER);
|
map.register(BigDecimal.class, BIG_DECIMAL_TYPE_ADAPTER);
|
||||||
map.register(BigInteger.class, BIG_INTEGER_TYPE_ADAPTER);
|
map.register(BigInteger.class, BIG_INTEGER_TYPE_ADAPTER);
|
||||||
|
|
||||||
// Add primitive serializers
|
// Add primitive serializers
|
||||||
map.register(Boolean.class, BOOLEAN_TYPE_ADAPTER);
|
map.register(Boolean.class, BOOLEAN_TYPE_ADAPTER);
|
||||||
map.register(boolean.class, BOOLEAN_TYPE_ADAPTER);
|
map.register(boolean.class, BOOLEAN_TYPE_ADAPTER);
|
||||||
|
@ -156,7 +156,7 @@ final class DefaultTypeAdapters {
|
||||||
map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER);
|
map.register(GregorianCalendar.class, GREGORIAN_CALENDAR_TYPE_ADAPTER);
|
||||||
map.register(BigDecimal.class, wrapDeserializer(BIG_DECIMAL_TYPE_ADAPTER));
|
map.register(BigDecimal.class, wrapDeserializer(BIG_DECIMAL_TYPE_ADAPTER));
|
||||||
map.register(BigInteger.class, wrapDeserializer(BIG_INTEGER_TYPE_ADAPTER));
|
map.register(BigInteger.class, wrapDeserializer(BIG_INTEGER_TYPE_ADAPTER));
|
||||||
|
|
||||||
// Add primitive deserializers
|
// Add primitive deserializers
|
||||||
map.register(Boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER));
|
map.register(Boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER));
|
||||||
map.register(boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER));
|
map.register(boolean.class, wrapDeserializer(BOOLEAN_TYPE_ADAPTER));
|
||||||
|
@ -196,7 +196,7 @@ final class DefaultTypeAdapters {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
private static JsonDeserializer<?> wrapDeserializer(JsonDeserializer<?> deserializer) {
|
private static JsonDeserializer<?> wrapDeserializer(JsonDeserializer<?> deserializer) {
|
||||||
return new JsonDeserializerExceptionWrapper(deserializer);
|
return new JsonDeserializerExceptionWrapper(deserializer);
|
||||||
}
|
}
|
||||||
|
@ -204,26 +204,26 @@ final class DefaultTypeAdapters {
|
||||||
static ParameterizedTypeHandlerMap<JsonSerializer<?>> getDefaultSerializers() {
|
static ParameterizedTypeHandlerMap<JsonSerializer<?>> getDefaultSerializers() {
|
||||||
return getDefaultSerializers(false, LongSerializationPolicy.DEFAULT);
|
return getDefaultSerializers(false, LongSerializationPolicy.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParameterizedTypeHandlerMap<JsonSerializer<?>> getDefaultSerializers(
|
static ParameterizedTypeHandlerMap<JsonSerializer<?>> getDefaultSerializers(
|
||||||
boolean serializeSpecialFloatingPointValues, LongSerializationPolicy longSerializationPolicy) {
|
boolean serializeSpecialFloatingPointValues, LongSerializationPolicy longSerializationPolicy) {
|
||||||
ParameterizedTypeHandlerMap<JsonSerializer<?>> serializers =
|
ParameterizedTypeHandlerMap<JsonSerializer<?>> serializers =
|
||||||
new ParameterizedTypeHandlerMap<JsonSerializer<?>>();
|
new ParameterizedTypeHandlerMap<JsonSerializer<?>>();
|
||||||
|
|
||||||
// Double primitive
|
// Double primitive
|
||||||
DefaultTypeAdapters.DoubleSerializer doubleSerializer =
|
DefaultTypeAdapters.DoubleSerializer doubleSerializer =
|
||||||
new DefaultTypeAdapters.DoubleSerializer(serializeSpecialFloatingPointValues);
|
new DefaultTypeAdapters.DoubleSerializer(serializeSpecialFloatingPointValues);
|
||||||
serializers.registerIfAbsent(Double.class, doubleSerializer);
|
serializers.registerIfAbsent(Double.class, doubleSerializer);
|
||||||
serializers.registerIfAbsent(double.class, doubleSerializer);
|
serializers.registerIfAbsent(double.class, doubleSerializer);
|
||||||
|
|
||||||
// Float primitive
|
// Float primitive
|
||||||
DefaultTypeAdapters.FloatSerializer floatSerializer =
|
DefaultTypeAdapters.FloatSerializer floatSerializer =
|
||||||
new DefaultTypeAdapters.FloatSerializer(serializeSpecialFloatingPointValues);
|
new DefaultTypeAdapters.FloatSerializer(serializeSpecialFloatingPointValues);
|
||||||
serializers.registerIfAbsent(Float.class, floatSerializer);
|
serializers.registerIfAbsent(Float.class, floatSerializer);
|
||||||
serializers.registerIfAbsent(float.class, floatSerializer);
|
serializers.registerIfAbsent(float.class, floatSerializer);
|
||||||
|
|
||||||
// Long primitive
|
// Long primitive
|
||||||
DefaultTypeAdapters.LongSerializer longSerializer =
|
DefaultTypeAdapters.LongSerializer longSerializer =
|
||||||
new DefaultTypeAdapters.LongSerializer(longSerializationPolicy);
|
new DefaultTypeAdapters.LongSerializer(longSerializationPolicy);
|
||||||
serializers.registerIfAbsent(Long.class, longSerializer);
|
serializers.registerIfAbsent(Long.class, longSerializer);
|
||||||
serializers.registerIfAbsent(long.class, longSerializer);
|
serializers.registerIfAbsent(long.class, longSerializer);
|
||||||
|
@ -231,11 +231,11 @@ final class DefaultTypeAdapters {
|
||||||
serializers.registerIfAbsent(DEFAULT_SERIALIZERS);
|
serializers.registerIfAbsent(DEFAULT_SERIALIZERS);
|
||||||
return serializers;
|
return serializers;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParameterizedTypeHandlerMap<JsonDeserializer<?>> getDefaultDeserializers() {
|
static ParameterizedTypeHandlerMap<JsonDeserializer<?>> getDefaultDeserializers() {
|
||||||
return DEFAULT_DESERIALIZERS;
|
return DEFAULT_DESERIALIZERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ParameterizedTypeHandlerMap<InstanceCreator<?>> getDefaultInstanceCreators() {
|
static ParameterizedTypeHandlerMap<InstanceCreator<?>> getDefaultInstanceCreators() {
|
||||||
return DEFAULT_INSTANCE_CREATORS;
|
return DEFAULT_INSTANCE_CREATORS;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ final class DefaultTypeAdapters {
|
||||||
DefaultDateTypeAdapter(final String datePattern) {
|
DefaultDateTypeAdapter(final String datePattern) {
|
||||||
this.format = new SimpleDateFormat(datePattern);
|
this.format = new SimpleDateFormat(datePattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultDateTypeAdapter(final int style) {
|
DefaultDateTypeAdapter(final int style) {
|
||||||
this.format = DateFormat.getDateInstance(style);
|
this.format = DateFormat.getDateInstance(style);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ final class DefaultTypeAdapters {
|
||||||
throw new JsonSyntaxException(e);
|
throw new JsonSyntaxException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
@ -304,7 +304,8 @@ final class DefaultTypeAdapters {
|
||||||
String dateFormatAsString = format.format(src);
|
String dateFormatAsString = format.format(src);
|
||||||
return new JsonPrimitive(dateFormatAsString);
|
return new JsonPrimitive(dateFormatAsString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.sql.Date deserialize(JsonElement json, Type typeOfT,
|
public java.sql.Date deserialize(JsonElement json, Type typeOfT,
|
||||||
JsonDeserializationContext context) throws JsonParseException {
|
JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (!(json instanceof JsonPrimitive)) {
|
if (!(json instanceof JsonPrimitive)) {
|
||||||
|
@ -356,7 +357,7 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class GregorianCalendarTypeAdapter
|
private static class GregorianCalendarTypeAdapter
|
||||||
implements JsonSerializer<GregorianCalendar>, JsonDeserializer<GregorianCalendar> {
|
implements JsonSerializer<GregorianCalendar>, JsonDeserializer<GregorianCalendar> {
|
||||||
|
|
||||||
private static final String YEAR = "year";
|
private static final String YEAR = "year";
|
||||||
|
@ -373,11 +374,11 @@ final class DefaultTypeAdapters {
|
||||||
obj.addProperty(MONTH, src.get(Calendar.MONTH));
|
obj.addProperty(MONTH, src.get(Calendar.MONTH));
|
||||||
obj.addProperty(DAY_OF_MONTH, src.get(Calendar.DAY_OF_MONTH));
|
obj.addProperty(DAY_OF_MONTH, src.get(Calendar.DAY_OF_MONTH));
|
||||||
obj.addProperty(HOUR_OF_DAY, src.get(Calendar.HOUR_OF_DAY));
|
obj.addProperty(HOUR_OF_DAY, src.get(Calendar.HOUR_OF_DAY));
|
||||||
obj.addProperty(MINUTE, src.get(Calendar.MINUTE));
|
obj.addProperty(MINUTE, src.get(Calendar.MINUTE));
|
||||||
obj.addProperty(SECOND, src.get(Calendar.SECOND));
|
obj.addProperty(SECOND, src.get(Calendar.SECOND));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GregorianCalendar deserialize(JsonElement json, Type typeOfT,
|
public GregorianCalendar deserialize(JsonElement json, Type typeOfT,
|
||||||
JsonDeserializationContext context) throws JsonParseException {
|
JsonDeserializationContext context) throws JsonParseException {
|
||||||
JsonObject obj = json.getAsJsonObject();
|
JsonObject obj = json.getAsJsonObject();
|
||||||
|
@ -385,17 +386,17 @@ final class DefaultTypeAdapters {
|
||||||
int month = obj.get(MONTH).getAsInt();
|
int month = obj.get(MONTH).getAsInt();
|
||||||
int dayOfMonth = obj.get(DAY_OF_MONTH).getAsInt();
|
int dayOfMonth = obj.get(DAY_OF_MONTH).getAsInt();
|
||||||
int hourOfDay = obj.get(HOUR_OF_DAY).getAsInt();
|
int hourOfDay = obj.get(HOUR_OF_DAY).getAsInt();
|
||||||
int minute = obj.get(MINUTE).getAsInt();
|
int minute = obj.get(MINUTE).getAsInt();
|
||||||
int second = obj.get(SECOND).getAsInt();
|
int second = obj.get(SECOND).getAsInt();
|
||||||
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
|
return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return GregorianCalendarTypeAdapter.class.getSimpleName();
|
return GregorianCalendarTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static class EnumTypeAdapter<T extends Enum<T>>
|
private static class EnumTypeAdapter<T extends Enum<T>>
|
||||||
implements JsonSerializer<T>, JsonDeserializer<T> {
|
implements JsonSerializer<T>, JsonDeserializer<T> {
|
||||||
|
@ -432,7 +433,7 @@ final class DefaultTypeAdapters {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return UrlTypeAdapter.class.getSimpleName();
|
return UrlTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UriTypeAdapter implements JsonSerializer<URI>, JsonDeserializer<URI> {
|
private static class UriTypeAdapter implements JsonSerializer<URI>, JsonDeserializer<URI> {
|
||||||
|
@ -452,14 +453,14 @@ final class DefaultTypeAdapters {
|
||||||
return UriTypeAdapter.class.getSimpleName();
|
return UriTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class UuidTypeAdapter implements JsonSerializer<UUID>, JsonDeserializer<UUID> {
|
private static class UuidTypeAdapter implements JsonSerializer<UUID>, JsonDeserializer<UUID> {
|
||||||
public JsonElement serialize(UUID src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(UUID src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src.toString());
|
return new JsonPrimitive(src.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public UUID deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
return UUID.fromString(json.getAsString());
|
return UUID.fromString(json.getAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,7 +470,7 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LocaleTypeAdapter
|
private static class LocaleTypeAdapter
|
||||||
implements JsonSerializer<Locale>, JsonDeserializer<Locale> {
|
implements JsonSerializer<Locale>, JsonDeserializer<Locale> {
|
||||||
public JsonElement serialize(Locale src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Locale src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src.toString());
|
return new JsonPrimitive(src.toString());
|
||||||
|
@ -506,8 +507,8 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
private static class CollectionTypeAdapter implements JsonSerializer<Collection>,
|
private static class CollectionTypeAdapter implements JsonSerializer<Collection>,
|
||||||
JsonDeserializer<Collection>, InstanceCreator<Collection> {
|
JsonDeserializer<Collection>, InstanceCreator<Collection> {
|
||||||
public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
|
@ -516,7 +517,7 @@ final class DefaultTypeAdapters {
|
||||||
JsonArray array = new JsonArray();
|
JsonArray array = new JsonArray();
|
||||||
Type childGenericType = null;
|
Type childGenericType = null;
|
||||||
if (typeOfSrc instanceof ParameterizedType) {
|
if (typeOfSrc instanceof ParameterizedType) {
|
||||||
childGenericType = new TypeInfoCollection(typeOfSrc).getElementType();
|
childGenericType = new TypeInfoCollection(typeOfSrc).getElementType();
|
||||||
}
|
}
|
||||||
for (Object child : src) {
|
for (Object child : src) {
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
|
@ -531,12 +532,12 @@ final class DefaultTypeAdapters {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection deserialize(JsonElement json, Type typeOfT,
|
public Collection deserialize(JsonElement json, Type typeOfT,
|
||||||
JsonDeserializationContext context) throws JsonParseException {
|
JsonDeserializationContext context) throws JsonParseException {
|
||||||
if (json.isJsonNull()) {
|
if (json.isJsonNull()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
|
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
|
||||||
// This handles cases where users are using their own subclass of Collection.
|
// This handles cases where users are using their own subclass of Collection.
|
||||||
Collection collection = constructCollectionType(typeOfT, context);
|
Collection collection = constructCollectionType(typeOfT, context);
|
||||||
Type childType = new TypeInfoCollection(typeOfT).getElementType();
|
Type childType = new TypeInfoCollection(typeOfT).getElementType();
|
||||||
|
@ -551,8 +552,8 @@ final class DefaultTypeAdapters {
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection constructCollectionType(Type collectionType,
|
private Collection constructCollectionType(Type collectionType,
|
||||||
JsonDeserializationContext context) {
|
JsonDeserializationContext context) {
|
||||||
JsonDeserializationContextDefault contextImpl = (JsonDeserializationContextDefault) context;
|
JsonDeserializationContextDefault contextImpl = (JsonDeserializationContextDefault) context;
|
||||||
ObjectConstructor objectConstructor = contextImpl.getObjectConstructor();
|
ObjectConstructor objectConstructor = contextImpl.getObjectConstructor();
|
||||||
return (Collection) objectConstructor.construct(collectionType);
|
return (Collection) objectConstructor.construct(collectionType);
|
||||||
|
@ -560,24 +561,24 @@ final class DefaultTypeAdapters {
|
||||||
|
|
||||||
public Collection createInstance(Type type) {
|
public Collection createInstance(Type type) {
|
||||||
return new LinkedList();
|
return new LinkedList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class PropertiesCreator implements InstanceCreator<Properties> {
|
private static class PropertiesCreator implements InstanceCreator<Properties> {
|
||||||
public Properties createInstance(Type type) {
|
public Properties createInstance(Type type) {
|
||||||
return new Properties();
|
return new Properties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
static class MapTypeAdapter implements JsonSerializer<Map>, JsonDeserializer<Map>,
|
static class MapTypeAdapter implements JsonSerializer<Map>, JsonDeserializer<Map>,
|
||||||
InstanceCreator<Map> {
|
InstanceCreator<Map> {
|
||||||
|
|
||||||
public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Map src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
JsonObject map = new JsonObject();
|
JsonObject map = new JsonObject();
|
||||||
Type childGenericType = null;
|
Type childGenericType = null;
|
||||||
if (typeOfSrc instanceof ParameterizedType) {
|
if (typeOfSrc instanceof ParameterizedType) {
|
||||||
childGenericType = new TypeInfoMap(typeOfSrc).getValueType();
|
childGenericType = new TypeInfoMap(typeOfSrc).getValueType();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry entry : (Set<Map.Entry>) src.entrySet()) {
|
for (Map.Entry entry : (Set<Map.Entry>) src.entrySet()) {
|
||||||
|
@ -598,7 +599,7 @@ final class DefaultTypeAdapters {
|
||||||
|
|
||||||
public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public Map deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
|
// Use ObjectConstructor to create instance instead of hard-coding a specific type.
|
||||||
// This handles cases where users are using their own subclass of Map.
|
// This handles cases where users are using their own subclass of Map.
|
||||||
Map<Object, Object> map = constructMapType(typeOfT, context);
|
Map<Object, Object> map = constructMapType(typeOfT, context);
|
||||||
TypeInfoMap mapTypeInfo = new TypeInfoMap(typeOfT);
|
TypeInfoMap mapTypeInfo = new TypeInfoMap(typeOfT);
|
||||||
|
@ -610,16 +611,16 @@ final class DefaultTypeAdapters {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map constructMapType(Type mapType, JsonDeserializationContext context) {
|
private Map constructMapType(Type mapType, JsonDeserializationContext context) {
|
||||||
JsonDeserializationContextDefault contextImpl = (JsonDeserializationContextDefault) context;
|
JsonDeserializationContextDefault contextImpl = (JsonDeserializationContextDefault) context;
|
||||||
ObjectConstructor objectConstructor = contextImpl.getObjectConstructor();
|
ObjectConstructor objectConstructor = contextImpl.getObjectConstructor();
|
||||||
return (Map) objectConstructor.construct(mapType);
|
return (Map) objectConstructor.construct(mapType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map createInstance(Type type) {
|
public Map createInstance(Type type) {
|
||||||
return new LinkedHashMap();
|
return new LinkedHashMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MapTypeAdapter.class.getSimpleName();
|
return MapTypeAdapter.class.getSimpleName();
|
||||||
|
@ -643,7 +644,7 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BigIntegerTypeAdapter
|
private static class BigIntegerTypeAdapter
|
||||||
implements JsonSerializer<BigInteger>, JsonDeserializer<BigInteger> {
|
implements JsonSerializer<BigInteger>, JsonDeserializer<BigInteger> {
|
||||||
|
|
||||||
public JsonElement serialize(BigInteger src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(BigInteger src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
@ -660,27 +661,27 @@ final class DefaultTypeAdapters {
|
||||||
return BigIntegerTypeAdapter.class.getSimpleName();
|
return BigIntegerTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class NumberTypeAdapter
|
private static class NumberTypeAdapter
|
||||||
implements JsonSerializer<Number>, JsonDeserializer<Number> {
|
implements JsonSerializer<Number>, JsonDeserializer<Number> {
|
||||||
public JsonElement serialize(Number src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Number src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Number deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public Number deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
return json.getAsNumber();
|
return json.getAsNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return NumberTypeAdapter.class.getSimpleName();
|
return NumberTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LongSerializer implements JsonSerializer<Long> {
|
private static class LongSerializer implements JsonSerializer<Long> {
|
||||||
private final LongSerializationPolicy longSerializationPolicy;
|
private final LongSerializationPolicy longSerializationPolicy;
|
||||||
|
|
||||||
private LongSerializer(LongSerializationPolicy longSerializationPolicy) {
|
private LongSerializer(LongSerializationPolicy longSerializationPolicy) {
|
||||||
this.longSerializationPolicy = longSerializationPolicy;
|
this.longSerializationPolicy = longSerializationPolicy;
|
||||||
}
|
}
|
||||||
|
@ -707,7 +708,7 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class IntegerTypeAdapter
|
private static class IntegerTypeAdapter
|
||||||
implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
|
implements JsonSerializer<Integer>, JsonDeserializer<Integer> {
|
||||||
public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
|
@ -734,7 +735,7 @@ final class DefaultTypeAdapters {
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
return json.getAsShort();
|
return json.getAsShort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ShortTypeAdapter.class.getSimpleName();
|
return ShortTypeAdapter.class.getSimpleName();
|
||||||
|
@ -767,7 +768,7 @@ final class DefaultTypeAdapters {
|
||||||
public JsonElement serialize(Float src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Float src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
if (!serializeSpecialFloatingPointValues) {
|
if (!serializeSpecialFloatingPointValues) {
|
||||||
if (Float.isNaN(src) || Float.isInfinite(src)) {
|
if (Float.isNaN(src) || Float.isInfinite(src)) {
|
||||||
throw new IllegalArgumentException(src
|
throw new IllegalArgumentException(src
|
||||||
+ " is not a valid float value as per JSON specification. To override this"
|
+ " is not a valid float value as per JSON specification. To override this"
|
||||||
+ " behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.");
|
+ " behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.");
|
||||||
}
|
}
|
||||||
|
@ -775,7 +776,7 @@ final class DefaultTypeAdapters {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FloatDeserializer implements JsonDeserializer<Float> {
|
private static class FloatDeserializer implements JsonDeserializer<Float> {
|
||||||
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
|
@ -798,7 +799,7 @@ final class DefaultTypeAdapters {
|
||||||
public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
if (!serializeSpecialFloatingPointValues) {
|
if (!serializeSpecialFloatingPointValues) {
|
||||||
if (Double.isNaN(src) || Double.isInfinite(src)) {
|
if (Double.isNaN(src) || Double.isInfinite(src)) {
|
||||||
throw new IllegalArgumentException(src
|
throw new IllegalArgumentException(src
|
||||||
+ " is not a valid double value as per JSON specification. To override this"
|
+ " is not a valid double value as per JSON specification. To override this"
|
||||||
+ " behavior, use GsonBuilder.serializeSpecialDoubleValues() method.");
|
+ " behavior, use GsonBuilder.serializeSpecialDoubleValues() method.");
|
||||||
}
|
}
|
||||||
|
@ -819,7 +820,7 @@ final class DefaultTypeAdapters {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CharacterTypeAdapter
|
private static class CharacterTypeAdapter
|
||||||
implements JsonSerializer<Character>, JsonDeserializer<Character> {
|
implements JsonSerializer<Character>, JsonDeserializer<Character> {
|
||||||
public JsonElement serialize(Character src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Character src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
|
@ -835,25 +836,25 @@ final class DefaultTypeAdapters {
|
||||||
return CharacterTypeAdapter.class.getSimpleName();
|
return CharacterTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class StringTypeAdapter
|
private static class StringTypeAdapter
|
||||||
implements JsonSerializer<String>, JsonDeserializer<String> {
|
implements JsonSerializer<String>, JsonDeserializer<String> {
|
||||||
public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
return json.getAsString();
|
return json.getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return StringTypeAdapter.class.getSimpleName();
|
return StringTypeAdapter.class.getSimpleName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BooleanTypeAdapter
|
private static class BooleanTypeAdapter
|
||||||
implements JsonSerializer<Boolean>, JsonDeserializer<Boolean> {
|
implements JsonSerializer<Boolean>, JsonDeserializer<Boolean> {
|
||||||
public JsonElement serialize(Boolean src, Type typeOfSrc, JsonSerializationContext context) {
|
public JsonElement serialize(Boolean src, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
return new JsonPrimitive(src);
|
return new JsonPrimitive(src);
|
||||||
|
|
|
@ -171,7 +171,7 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor {
|
||||||
/**
|
/**
|
||||||
* objTypePair.getObject() must not be null
|
* objTypePair.getObject() must not be null
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings("unchecked")
|
||||||
private JsonElement findAndInvokeCustomSerializer(ObjectTypePair objTypePair) {
|
private JsonElement findAndInvokeCustomSerializer(ObjectTypePair objTypePair) {
|
||||||
Pair<JsonSerializer<?>,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers);
|
Pair<JsonSerializer<?>,ObjectTypePair> pair = objTypePair.getMatchingHandler(serializers);
|
||||||
if (pair == null) {
|
if (pair == null) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user