List of usage examples for com.google.gson JsonElement getAsJsonObject
public JsonObject getAsJsonObject()
From source file:co.cask.cdap.proto.codec.IdTypeAdapter.java
License:Apache License
@Override public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject map = json.getAsJsonObject(); JsonElement elementTypeJson = map.get("elementType"); if (elementTypeJson == null) { throw new JsonParseException("Expected elementType in Id JSON"); }/*from w w w . j a v a 2s .com*/ String elementTypeString = elementTypeJson.getAsString(); EntityType type = EntityType.valueOf(elementTypeString); if (type == null) { throw new JsonParseException("Invalid elementType: " + elementTypeString); } return context.deserialize(json, type.getIdClass()); }
From source file:co.cask.cdap.proto.codec.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(); Resources driverResources = deserializeResources(jsonObj, "driver", context); Resources mapperResources = deserializeResources(jsonObj, "mapper", context); Resources reducerResources = deserializeResources(jsonObj, "reducer", context); 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 MapReduceSpecification(className, name, description, inputDataSet, outputDataSet, dataSets, properties, driverResources, mapperResources, reducerResources); }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
@Override public Id.NamespacedId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonObject id = jsonObj.getAsJsonObject("id"); String type = jsonObj.get("type").getAsString(); switch (type) { case "application": return deserializeApplicationId(id); case "program": return deserializeProgramId(id); case "flow": return deserializeFlowId(id); case "flowlet": return deserializeFlowletId(id); case "service": return deserializeServiceId(id); case "schedule": return deserializeSchedule(id); case "worker": return deserializeWorkerId(id); case "workflow": return deserializeWorkflowId(id); case "datasetinstance": return deserializeDatasetInstanceId(id); case "stream": return deserializeStreamId(id); case "view": return deserializeViewId(id); case "artifact": return deserializeArtifactId(id); default://w ww.j a v a2 s.com throw new UnsupportedOperationException(String.format( "Unsupported object of type %s found. Deserialization of only %s, %s, %s, %s, %s, %s, %s, " + "%s, %s, %s, %s, %s is supported.", type, Id.Application.class.getSimpleName(), Id.Program.class.getSimpleName(), Id.Flow.class.getSimpleName(), Id.Flow.Flowlet.class.getSimpleName(), Id.Service.class.getSimpleName(), Id.Schedule.class.getSimpleName(), Id.Worker.class.getSimpleName(), Id.Workflow.class.getSimpleName(), Id.DatasetInstance.class.getSimpleName(), Id.Stream.class.getSimpleName(), Id.Stream.View.class.getSimpleName(), Id.Artifact.class.getSimpleName())); } }
From source file:co.cask.cdap.proto.codec.ScheduleSpecificationCodec.java
License:Apache License
@Override public ScheduleSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonElement scheduleTypeJson = jsonObj.get("scheduleType"); ScheduleType scheduleType;// ww w.j a va2 s . c o m if (scheduleTypeJson == null) { // For backwards compatibility with spec persisted with older versions than 2.8, we need these lines scheduleType = null; } else { scheduleType = context.deserialize(jsonObj.get("scheduleType"), ScheduleType.class); } Schedule schedule = null; if (scheduleType == null) { JsonObject scheduleObj = jsonObj.get("schedule").getAsJsonObject(); String name = context.deserialize(scheduleObj.get("name"), String.class); String description = context.deserialize(scheduleObj.get("description"), String.class); String cronEntry = context.deserialize(scheduleObj.get("cronEntry"), String.class); schedule = Schedules.builder(name).setDescription(description).createTimeSchedule(cronEntry); } else { switch (scheduleType) { case TIME: schedule = context.deserialize(jsonObj.get("schedule"), TimeSchedule.class); break; case STREAM: schedule = context.deserialize(jsonObj.get("schedule"), StreamSizeSchedule.class); break; } } ScheduleProgramInfo program = context.deserialize(jsonObj.get("program"), ScheduleProgramInfo.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new ScheduleSpecification(schedule, program, properties); }
From source file:co.cask.cdap.proto.codec.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); Resources driverResources = deserializeResources(jsonObj, "driver", context); Resources executorResources = deserializeResources(jsonObj, "executor", context); return new SparkSpecification(className, name, description, mainClassName, properties, driverResources, executorResources);//from w w w.j a va 2 s . co m }
From source file:co.cask.cdap.proto.codec.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(); Set<String> datasets = deserializeSet(jsonObj.get("datasets"), context, String.class); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); return new DefaultWorkflowActionSpecification(className, name, description, properties, datasets); }
From source file:co.cask.cdap.proto.codec.WorkflowNodeCodec.java
License:Apache License
@Override public WorkflowNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); WorkflowNodeType type = context.deserialize(jsonObj.get("nodeType"), WorkflowNodeType.class); switch (type) { case ACTION:/*from w w w. j a v a 2 s . c o m*/ return context.deserialize(json, WorkflowActionNode.class); case FORK: return context.deserialize(json, WorkflowForkNode.class); case CONDITION: return context.deserialize(json, WorkflowConditionNode.class); } return null; }
From source file:co.cask.cdap.proto.codec.WorkflowNodeThrowableCodec.java
License:Apache License
@Override public WorkflowNodeThrowable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String message = jsonObj.get("message").getAsString(); JsonArray stackTraces = jsonObj.get("stackTraces").getAsJsonArray(); StackTraceElement[] stackTraceElements = context.deserialize(stackTraces, StackTraceElement[].class); JsonElement cause = jsonObj.get("cause"); WorkflowNodeThrowable dfc = null;/*from www . j a v a2 s.c o m*/ if (cause != null) { dfc = context.deserialize(cause, WorkflowNodeThrowable.class); } return new WorkflowNodeThrowable(className, message, stackTraceElements, dfc); }
From source file:co.cask.cdap.proto.codec.WorkflowSpecificationCodec.java
License:Apache License
@Override public WorkflowSpecification 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); List<WorkflowNode> nodes = deserializeList(jsonObj.get("nodes"), context, WorkflowNode.class); Map<String, DatasetCreationSpec> localDatasetSpec = deserializeMap(jsonObj.get("localDatasetSpecs"), context, DatasetCreationSpec.class); return new WorkflowSpecification(className, name, description, properties, nodes, localDatasetSpec); }
From source file:co.cask.cdap.proto.codec.WorkflowTokenDetailCodec.java
License:Apache License
@Override public WorkflowTokenDetail deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { Map<String, List<WorkflowTokenDetail.NodeValueDetail>> tokenData = new HashMap<>(); for (Map.Entry<String, JsonElement> entry : json.getAsJsonObject().entrySet()) { List<WorkflowTokenDetail.NodeValueDetail> nodeValueDetails = deserializeList(entry.getValue(), context, WorkflowTokenDetail.NodeValueDetail.class); tokenData.put(entry.getKey(), nodeValueDetails); }/*from w w w .j a v a 2 s . co m*/ return new WorkflowTokenDetail(tokenData); }