com.baggonius.gson.immutable.BaseCollectionDeserializer 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.Collection;
abstract class BaseCollectionDeserializer implements JsonDeserializer {
protected abstract E buildFrom(Collection> collection);
public E deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
try {
Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
Type parameterizedType = Types.collectionOf(typeArguments[0]).getType();
Collection> collection = context.deserialize(json, parameterizedType);
return buildFrom(collection);
} catch (Exception e) {
throw new ImmutableDeserializerException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy