com.eligible.json.deserializer.ClaimErrorDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eligible-java Show documentation
Show all versions of eligible-java Show documentation
Java bindings for Eligible APIs (https://eligible.com).
package com.eligible.json.deserializer;
import com.eligible.model.APIErrorResponse;
import com.eligible.model.claim.Error;
import com.eligible.net.APIResource;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
/**
* {@link JsonDeserializer} for deserializing {@link Error}.
*/
public class ClaimErrorDeserializer implements JsonDeserializer {
/**
* {@link Gson} deserializer for {@link APIErrorResponse}.
*/
public static final Gson GSON = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
/**
* {@inheritDoc}
*/
public Error deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
// Error could be a list of String.class, or a list of Error.class. Mapping String.class to Error.class
if (json.isJsonPrimitive()) {
return new Error(json.getAsString());
} else {
return GSON.fromJson(json, Error.class);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy