@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(); Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class); 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, plugins); }
@Override public JsonElement serialize(MapReduceSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("className", src.getClassName()); jsonObj.addProperty("name", src.getName()); jsonObj.addProperty("description", src.getDescription()); jsonObj.add("plugins", serializeMap(src.getPlugins(), context, Plugin.class)); if (src.getDriverResources() != null) { jsonObj.add("driverResources", context.serialize(src.getDriverResources())); } if (src.getMapperResources() != null) { jsonObj.add("mapperResources", context.serialize(src.getMapperResources())); } if (src.getReducerResources() != null) { jsonObj.add("reducerResources", context.serialize(src.getReducerResources())); } if (src.getInputDataSet() != null) { jsonObj.addProperty("inputDataSet", src.getInputDataSet()); } if (src.getOutputDataSet() != null) { jsonObj.addProperty("outputDataSet", src.getOutputDataSet()); } jsonObj.add("datasets", serializeSet(src.getDataSets(), context, String.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); return jsonObj; }
public static GsonBuilder addTypeAdapters(GsonBuilder builder) { return builder .registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) .registerTypeAdapter(ApplicationSpecification.class, new ApplicationSpecificationCodec()) .registerTypeAdapter(MapReduceSpecification.class, new MapReduceSpecificationCodec()) .registerTypeAdapter(SparkSpecification.class, new SparkSpecificationCodec()) .registerTypeAdapter(WorkflowSpecification.class, new WorkflowSpecificationCodec()) .registerTypeAdapter(WorkflowNode.class, new WorkflowNodeCodec()) .registerTypeAdapter(CustomActionSpecification.class, new CustomActionSpecificationCodec()) .registerTypeAdapter(ConditionSpecification.class, new ConditionSpecificationCodec()) .registerTypeAdapter(ServiceSpecification.class, new ServiceSpecificationCodec()) .registerTypeAdapter(WorkerSpecification.class, new WorkerSpecificationCodec()) .registerTypeAdapter(BasicThrowable.class, new BasicThrowableCodec()) .registerTypeAdapter(Trigger.class, new TriggerCodec()) .registerTypeAdapter(SatisfiableTrigger.class, new TriggerCodec()) .registerTypeAdapter(Constraint.class, new ConstraintCodec()) .registerTypeAdapterFactory(new AppSpecTypeAdapterFactory()); }
@Override public JsonElement serialize(MapReduceSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("className", src.getClassName()); jsonObj.addProperty("name", src.getName()); jsonObj.addProperty("description", src.getDescription()); jsonObj.add("plugins", serializeMap(src.getPlugins(), context, Plugin.class)); if (src.getDriverResources() != null) { jsonObj.add("driverResources", context.serialize(src.getDriverResources())); } if (src.getMapperResources() != null) { jsonObj.add("mapperResources", context.serialize(src.getMapperResources())); } if (src.getReducerResources() != null) { jsonObj.add("reducerResources", context.serialize(src.getReducerResources())); } if (src.getInputDataSet() != null) { jsonObj.addProperty("inputDataSet", src.getInputDataSet()); } if (src.getOutputDataSet() != null) { jsonObj.addProperty("outputDataSet", src.getOutputDataSet()); } jsonObj.add("datasets", serializeSet(src.getDataSets(), context, String.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); return jsonObj; }
public static GsonBuilder addTypeAdapters(GsonBuilder builder) { return builder .registerTypeAdapter(Schema.class, new SchemaTypeAdapter()) .registerTypeAdapter(ApplicationSpecification.class, new ApplicationSpecificationCodec()) .registerTypeAdapter(FlowSpecification.class, new FlowSpecificationCodec()) .registerTypeAdapter(FlowletSpecification.class, new FlowletSpecificationCodec()) .registerTypeAdapter(MapReduceSpecification.class, new MapReduceSpecificationCodec()) .registerTypeAdapter(SparkSpecification.class, new SparkSpecificationCodec()) .registerTypeAdapter(WorkflowSpecification.class, new WorkflowSpecificationCodec()) .registerTypeAdapter(WorkflowNode.class, new WorkflowNodeCodec()) .registerTypeAdapter(CustomActionSpecification.class, new CustomActionSpecificationCodec()) .registerTypeAdapter(ConditionSpecification.class, new ConditionSpecificationCodec()) .registerTypeAdapter(ServiceSpecification.class, new ServiceSpecificationCodec()) .registerTypeAdapter(WorkerSpecification.class, new WorkerSpecificationCodec()) .registerTypeAdapter(BasicThrowable.class, new BasicThrowableCodec()) .registerTypeAdapter(Trigger.class, new TriggerCodec()) .registerTypeAdapter(SatisfiableTrigger.class, new TriggerCodec()) .registerTypeAdapter(Constraint.class, new ConstraintCodec()) .registerTypeAdapterFactory(new AppSpecTypeAdapterFactory()); }
@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(); Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class); 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, plugins); }