List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:co.cask.cdap.internal.app.AbstractSpecificationCodec.java
License:Apache License
protected final <V> Set<V> deserializeSet(JsonElement json, JsonDeserializationContext context, Class<V> valueType) { Type type = new TypeToken<Set<V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();/*w w w. ja v a2s . com*/ Set<V> set = context.deserialize(json, type); return set == null ? ImmutableSet.<V>of() : set; }
From source file:co.cask.cdap.internal.app.AbstractSpecificationCodec.java
License:Apache License
protected final <V> List<V> deserializeList(JsonElement json, JsonDeserializationContext context, Class<V> valueType) { Type type = new TypeToken<List<V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();//ww w. j a v a 2s. co m List<V> list = context.deserialize(json, type); return list == null ? ImmutableList.<V>of() : list; }
From source file:co.cask.cdap.internal.app.ApplicationSpecificationCodec.java
License:Apache License
@Override public ApplicationSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); String configuration = null;//from ww w. j a v a2 s. c o m if (jsonObj.has("configuration")) { configuration = jsonObj.get("configuration").getAsString(); } ArtifactId artifactId = context.deserialize(jsonObj.get("artifactId"), ArtifactId.class); Map<String, StreamSpecification> streams = deserializeMap(jsonObj.get("streams"), context, StreamSpecification.class); Map<String, String> datasetModules = deserializeMap(jsonObj.get("datasetModules"), context, String.class); Map<String, DatasetCreationSpec> datasetInstances = deserializeMap(jsonObj.get("datasetInstances"), context, DatasetCreationSpec.class); Map<String, FlowSpecification> flows = deserializeMap(jsonObj.get("flows"), context, FlowSpecification.class); Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context, MapReduceSpecification.class); Map<String, SparkSpecification> sparks = deserializeMap(jsonObj.get("sparks"), context, SparkSpecification.class); Map<String, WorkflowSpecification> workflows = deserializeMap(jsonObj.get("workflows"), context, WorkflowSpecification.class); Map<String, ServiceSpecification> services = deserializeMap(jsonObj.get("services"), context, ServiceSpecification.class); Map<String, ScheduleSpecification> schedules = deserializeMap(jsonObj.get("schedules"), context, ScheduleSpecification.class); Map<String, WorkerSpecification> workers = deserializeMap(jsonObj.get("workers"), context, WorkerSpecification.class); Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class); return new DefaultApplicationSpecification(name, description, configuration, artifactId, streams, datasetModules, datasetInstances, flows, mapReduces, sparks, workflows, services, schedules, workers, plugins); }
From source file:co.cask.cdap.internal.app.FlowletSpecificationCodec.java
License:Apache License
@Override public FlowletSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); FailurePolicy policy = FailurePolicy.valueOf(jsonObj.get("failurePolicy").getAsString()); Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), new TypeToken<ResourceSpecification>() { }.getType());/*from w w w . j a v a 2 s.c o m*/ return new DefaultFlowletSpecification(className, name, description, policy, dataSets, properties, resources); }
From source file:co.cask.cdap.internal.app.ProcedureSpecificationCodec.java
License:Apache License
@Override public ProcedureSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); ResourceSpecification resourceSpec = context.deserialize(jsonObj.get("resources"), new TypeToken<ResourceSpecification>() { }.getType());/* www . j ava2 s. c o m*/ JsonElement instanceElem = jsonObj.get("instances"); int instances = (instanceElem == null || instanceElem.isJsonNull()) ? 1 : jsonObj.get("instances").getAsInt(); return new DefaultProcedureSpecification(className, name, description, dataSets, properties, resourceSpec, instances); }
From source file:co.cask.cdap.internal.app.runtime.codec.ArgumentsCodec.java
License:Apache License
@Override public Arguments deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Map<String, String> args = context.deserialize(json, MAP_STRING_STRING_TYPE); return new BasicArguments(args); }
From source file:co.cask.cdap.internal.app.runtime.codec.ProgramOptionsCodec.java
License:Apache License
@Override public ProgramOptions deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = jsonObj.get("name").getAsString(); Arguments arguments = context.deserialize(jsonObj.get("arguments"), Arguments.class); Arguments userArguments = context.deserialize(jsonObj.get("userArguments"), Arguments.class); boolean debug = jsonObj.get("debug").getAsBoolean(); return new SimpleProgramOptions(name, arguments, userArguments, debug); }
From source file:co.cask.cdap.internal.app.ServiceSpecificationCodec.java
License:Apache License
@Override public ServiceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = (JsonObject) json; if (isOldSpec(jsonObj)) { return decodeOldSpec(jsonObj); }//w ww .j av a 2 s . c om String className = jsonObj.get("className").getAsString(); String name = jsonObj.get("name").getAsString(); String description = jsonObj.get("description").getAsString(); Map<String, HttpServiceHandlerSpecification> handlers = deserializeMap(jsonObj.get("handlers"), context, HttpServiceHandlerSpecification.class); Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class); int instances = jsonObj.get("instances").getAsInt(); return new ServiceSpecification(className, name, description, handlers, resources, instances); }
From source file:co.cask.cdap.proto.codec.AbstractSpecificationCodec.java
License:Apache License
protected final <V> Map<String, V> deserializeMap(JsonElement json, JsonDeserializationContext context, Class<V> valueType) { Type type = new TypeToken<Map<String, V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();/*ww w. j a v a2s . co m*/ Map<String, V> map = context.deserialize(json, type); return map == null ? Collections.<String, V>emptyMap() : map; }
From source file:co.cask.cdap.proto.codec.AbstractSpecificationCodec.java
License:Apache License
protected final <V> Set<V> deserializeSet(JsonElement json, JsonDeserializationContext context, Class<V> valueType) { Type type = new TypeToken<Set<V>>() { }.where(new TypeParameter<V>() { }, valueType).getType();// w w w.j a v a 2 s .c o m Set<V> set = context.deserialize(json, type); return set == null ? Collections.<V>emptySet() : set; }