
org.johnnei.enjin.internal.gson.OptionalDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enjin-api-impl Show documentation
Show all versions of enjin-api-impl Show documentation
The specification of the Enjin API
The newest version!
package org.johnnei.enjin.internal.gson;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Optional;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
public class OptionalDeserializer implements JsonDeserializer> {
@Override
public Optional> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
final Type genericType = ((ParameterizedType) typeOfT).getActualTypeArguments()[0];
final Object value = context.deserialize(json, genericType);
return Optional.ofNullable(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy