com.baggonius.gson.immutable.BaseMapDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of guava-gson-serializers Show documentation
Show all versions of guava-gson-serializers Show documentation
Serialization support with GSON for Guava immutable collections
The newest version!
package com.baggonius.gson.immutable;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.baggonius.gson.common.ImmutableDeserializerException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;
abstract class BaseMapDeserializer implements JsonDeserializer {
protected abstract E buildFrom(Map, ?> map);
public E deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
try {
Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
Type parameterizedType = Types.hashMapOf(typeArguments[0], typeArguments[1]).getType();
Map, ?> map = context.deserialize(json, parameterizedType);
return buildFrom(map);
} catch (Exception e) {
throw new ImmutableDeserializerException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy