Back to project page RestIt.
The source code is released under:
Apache License
If you think the Android project RestIt listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.restit.model.serialization; //from w ww .j a v a 2s. c o m import java.lang.reflect.Type; import org.restit.model.ServerError; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; public class ServerErrorDeserializer implements JsonDeserializer<ServerError> { @Override public ServerError deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException { if(jsonElement == null) return null; String message = null; if(jsonElement.isJsonPrimitive()) { message = jsonElement.getAsString(); } else { //nested object JsonObject jsonObject = jsonElement.getAsJsonObject(); message = jsonObject.get(jsonObject.entrySet().iterator().next().getKey()).getAsString(); } ServerError error = new ServerError(); error.setMessage(message); return error; } }