Search in sources :

Example 51 with JsonParseException

use of com.google.gson.JsonParseException in project cdap by caskdata.

the class ProtoTriggerCodec method deserialize.

@Override
public Trigger deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    if (json == null) {
        return null;
    }
    if (!(json instanceof JsonObject)) {
        throw new JsonParseException("Expected a JsonObject but found a " + json.getClass().getName());
    }
    JsonObject object = (JsonObject) json;
    JsonElement typeJson = object.get("type");
    ProtoTrigger.Type triggerType = context.deserialize(typeJson, ProtoTrigger.Type.class);
    Class<? extends Trigger> subClass = typeClassMap.get(triggerType);
    if (subClass == null) {
        throw new JsonParseException("Unable to map trigger type " + triggerType + " to a trigger class");
    }
    ProtoTrigger trigger = context.deserialize(json, subClass);
    trigger.validate();
    return trigger;
}
Also used : JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException)

Example 52 with JsonParseException

use of com.google.gson.JsonParseException in project cdap by caskdata.

the class EntityIdTypeAdapter method deserialize.

@Override
public EntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject map = json.getAsJsonObject();
    JsonElement entityTypeJson = map.get("entity");
    if (entityTypeJson == null) {
        throw new JsonParseException("Expected entity in EntityId JSON");
    }
    String entityTypeString = entityTypeJson.getAsString();
    EntityType type = EntityType.valueOf(entityTypeString);
    if (type == null) {
        throw new JsonParseException("Invalid entity: " + entityTypeString);
    }
    return context.deserialize(json, type.getIdClass());
}
Also used : EntityType(co.cask.cdap.proto.element.EntityType) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException)

Aggregations

JsonParseException (com.google.gson.JsonParseException)52 JsonObject (com.google.gson.JsonObject)20 IOException (java.io.IOException)14 JsonElement (com.google.gson.JsonElement)13 Gson (com.google.gson.Gson)12 GsonBuilder (com.google.gson.GsonBuilder)8 JsonArray (com.google.gson.JsonArray)7 Type (java.lang.reflect.Type)7 JsonParser (com.google.gson.JsonParser)6 JsonDeserializationContext (com.google.gson.JsonDeserializationContext)4 SocketTimeoutException (java.net.SocketTimeoutException)4 ArrayList (java.util.ArrayList)4 Resources (android.content.res.Resources)3 TextView (android.widget.TextView)3 RutgersServerIOException (com.tevinjeffrey.rutgersct.rutgersapi.exceptions.RutgersServerIOException)3 UnknownHostException (java.net.UnknownHostException)3 Date (java.util.Date)3 Uri (android.net.Uri)2 ParcelFileDescriptor (android.os.ParcelFileDescriptor)2 PluginClass (co.cask.cdap.api.plugin.PluginClass)2