@Override public WorkerSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = (JsonObject) json; 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); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class); Set<String> datasets = deserializeSet(jsonObj.get("datasets"), context, String.class); int instances = jsonObj.get("instances").getAsInt(); return new WorkerSpecification(className, name, description, properties, datasets, resources, instances, plugins); } }
@Override public JsonElement serialize(WorkerSpecification spec, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("className", spec.getClassName()); jsonObj.addProperty("name", spec.getName()); jsonObj.addProperty("description", spec.getDescription()); jsonObj.add("plugins", serializeMap(spec.getPlugins(), context, Plugin.class)); jsonObj.add("properties", serializeMap(spec.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(spec.getResources(), Resources.class)); jsonObj.add("datasets", serializeSet(spec.getDatasets(), context, String.class)); jsonObj.addProperty("instances", spec.getInstances()); 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(WorkerSpecification spec, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.addProperty("className", spec.getClassName()); jsonObj.addProperty("name", spec.getName()); jsonObj.addProperty("description", spec.getDescription()); jsonObj.add("plugins", serializeMap(spec.getPlugins(), context, Plugin.class)); jsonObj.add("properties", serializeMap(spec.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(spec.getResources(), Resources.class)); jsonObj.add("datasets", serializeSet(spec.getDatasets(), context, String.class)); jsonObj.addProperty("instances", spec.getInstances()); 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 WorkerSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = (JsonObject) json; 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); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class); Set<String> datasets = deserializeSet(jsonObj.get("datasets"), context, String.class); int instances = jsonObj.get("instances").getAsInt(); return new WorkerSpecification(className, name, description, properties, datasets, resources, instances, plugins); } }