List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
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 www . ja v a 2s . 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 a2s . c om*/ return new DefaultFlowletSpecification(className, name, description, policy, dataSets, properties, resources); }
From source file:co.cask.cdap.internal.app.FlowSpecificationCodec.java
License:Apache License
@Override public FlowSpecification 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(); Map<String, FlowletDefinition> flowlets = deserializeMap(jsonObj.get("flowlets"), context, FlowletDefinition.class); List<FlowletConnection> connections = deserializeList(jsonObj.get("connections"), context, FlowletConnection.class); return new DefaultFlowSpecification(className, name, description, flowlets, connections); }
From source file:co.cask.cdap.internal.app.MapReduceSpecificationCodec.java
License:Apache License
@Override public MapReduceSpecification 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(); int mapperMemoryMB = jsonObj.get("mapperMemoryMB").getAsInt(); int reducerMemoryMB = jsonObj.get("reducerMemoryMB").getAsInt(); JsonElement inputDataSetElem = jsonObj.get("inputDataSet"); String inputDataSet = inputDataSetElem == null ? null : inputDataSetElem.getAsString(); JsonElement outputDataSetElem = jsonObj.get("outputDataSet"); String outputDataSet = outputDataSetElem == null ? null : outputDataSetElem.getAsString(); Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultMapReduceSpecification(className, name, description, inputDataSet, outputDataSet, dataSets, properties, mapperMemoryMB, reducerMemoryMB); }
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());//from ww w . ja v a 2 s .com 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.ResourceSpecificationCodec.java
License:Apache License
@Override public ResourceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); int cores = jsonObj.get("virtualCores").getAsInt(); int memorySize = jsonObj.get("memoryMB").getAsInt(); return new Resources(memorySize, cores); }
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.ScheduleCodec.java
License:Apache License
@Override public Schedule 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 cronExpression = jsonObj.get("cronExpression").getAsString(); String action = jsonObj.get("action").getAsString(); return new Schedule(name, description, cronExpression, Schedule.Action.valueOf(action)); }
From source file:co.cask.cdap.internal.app.SparkSpecificationCodec.java
License:Apache License
@Override public SparkSpecification 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(); String mainClassName = jsonObj.get("mainClassName").getAsString(); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultSparkSpecification(className, name, description, mainClassName, properties); }
From source file:co.cask.cdap.internal.app.WorkflowActionSpecificationCodec.java
License:Apache License
@Override public WorkflowActionSpecification 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(); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultWorkflowActionSpecification(className, name, description, properties); }