@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()); Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), new TypeToken<ResourceSpecification>() { }.getType()); int maxInstances = jsonObj.get("maxInstances").getAsInt(); return new DefaultFlowletSpecification(className, name, description, policy, properties, resources, maxInstances); } }
@Override public JsonElement serialize(FlowletSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() { }.getType())); jsonObj.add("maxInstances", new JsonPrimitive(src.getMaxInstances())); return jsonObj; }