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;
}
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());
}
Aggregations