List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:com.continuuity.loom.codec.json.current.ProviderTypeCodec.java
License:Apache License
@Override public ProviderType deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = context.deserialize(jsonObj.get("name"), String.class); String description = context.deserialize(jsonObj.get("description"), String.class); Map<ParameterType, ParametersSpecification> parameters = context.deserialize(jsonObj.get("parameters"), new TypeToken<Map<ParameterType, ParametersSpecification>>() { }.getType());/*from w ww .java 2 s . c o m*/ Map<String, ResourceTypeSpecification> resourceTypes = context.deserialize(jsonObj.get("resourceTypes"), new TypeToken<Map<String, ResourceTypeSpecification>>() { }.getType()); return new ProviderType(name, description, parameters, resourceTypes); }
From source file:com.continuuity.loom.codec.json.current.ProvisionerCodec.java
License:Apache License
@Override public Provisioner deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); String host = context.deserialize(jsonObj.get("host"), String.class); Integer port = context.deserialize(jsonObj.get("port"), Integer.class); Integer capacityTotal = context.deserialize(jsonObj.get("capacityTotal"), Integer.class); Map<String, Integer> usage = context.deserialize(jsonObj.get("usage"), new TypeToken<Map<String, Integer>>() { }.getType());/*from w w w. ja va 2 s . co m*/ Map<String, Integer> assignments = context.deserialize(jsonObj.get("assignments"), new TypeToken<Map<String, Integer>>() { }.getType()); return new Provisioner(id, host, port, capacityTotal, usage, assignments); }
From source file:com.continuuity.loom.codec.json.current.ResourceTypeSpecificationCodec.java
License:Apache License
@Override public ResourceTypeSpecification deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); ResourceTypeFormat format = context.deserialize(jsonObj.get("format"), ResourceTypeFormat.class); return new ResourceTypeSpecification(format); }
From source file:com.continuuity.loom.codec.json.current.ServiceActionCodec.java
License:Apache License
@Override public ServiceAction deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String actionType = context.deserialize(jsonObj.get("type"), String.class); Map<String, String> fields = context.deserialize(jsonObj.get("fields"), new TypeToken<Map<String, String>>() { }.getType());//from ww w . j av a 2s .c o m return new ServiceAction(actionType, fields); }
From source file:com.continuuity.loom.codec.json.current.ServiceCodec.java
License:Apache License
@Override public Service deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = context.deserialize(jsonObj.get("name"), String.class); String description = context.deserialize(jsonObj.get("description"), String.class); ServiceDependencies dependencies = context.deserialize(jsonObj.get("dependencies"), ServiceDependencies.class); JsonObject provisioner = context.deserialize(jsonObj.get("provisioner"), JsonObject.class); Map<ProvisionerAction, ServiceAction> actions = Collections.emptyMap(); if (provisioner != null) { actions = context.deserialize(provisioner.get("actions"), new TypeToken<Map<ProvisionerAction, ServiceAction>>() { }.getType());//from ww w . j a v a2 s. c om } return new Service(name, description, dependencies, actions); }
From source file:com.continuuity.loom.codec.json.current.ServiceConstraintCodec.java
License:Apache License
@Override public ServiceConstraint deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonObject quantities = jsonObj.get("quantities").getAsJsonObject(); Integer min = context.deserialize(quantities.get("min"), Integer.class); Integer max = context.deserialize(quantities.get("max"), Integer.class); Integer stepSize = context.deserialize(quantities.get("stepSize"), Integer.class); ImmutablePair<Integer, Integer> ratio = stringToRatio( context.<String>deserialize(quantities.get("ratio"), String.class)); Set<String> requiredHardwareTypes = context.deserialize(jsonObj.get("hardwaretypes"), new TypeToken<Set<String>>() { }.getType());/* w w w.j a v a 2 s .co m*/ Set<String> requiredImageTypes = context.deserialize(jsonObj.get("imagetypes"), new TypeToken<Set<String>>() { }.getType()); return new ServiceConstraint(requiredHardwareTypes, requiredImageTypes, min, max, stepSize, ratio); }
From source file:com.continuuity.loom.codec.json.current.ServiceDependenciesCodec.java
License:Apache License
@Override public ServiceDependencies deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> provides = context.deserialize(jsonObj.get("provides"), new TypeToken<Set<String>>() { }.getType());//from w ww. j a v a2 s . c o m Set<String> conflicts = context.deserialize(jsonObj.get("conflicts"), new TypeToken<Set<String>>() { }.getType()); ServiceStageDependencies install = context.deserialize(jsonObj.get("install"), ServiceStageDependencies.class); ServiceStageDependencies runtime = context.deserialize(jsonObj.get("runtime"), ServiceStageDependencies.class); return new ServiceDependencies(provides, conflicts, install, runtime); }
From source file:com.continuuity.loom.codec.json.current.ServiceStageDependenciesCodec.java
License:Apache License
@Override public ServiceStageDependencies deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> requires = context.deserialize(jsonObj.get("requires"), new TypeToken<Set<String>>() { }.getType());//from w w w. j a va 2s. c o m Set<String> uses = context.deserialize(jsonObj.get("uses"), new TypeToken<Set<String>>() { }.getType()); return new ServiceStageDependencies(requires, uses); }
From source file:com.continuuity.loom.codec.json.current.TakeTaskRequestCodec.java
License:Apache License
@Override public TakeTaskRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String workerId = context.deserialize(jsonObj.get("workerId"), String.class); String provisionerId = context.deserialize(jsonObj.get("provisionerId"), String.class); String tenantId = context.deserialize(jsonObj.get("tenantId"), String.class); return new TakeTaskRequest(workerId, provisionerId, tenantId); }
From source file:com.continuuity.loom.codec.json.current.TaskConfigCodec.java
License:Apache License
@Override public TaskConfig deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { // make a copy since we'll be doing removes. This is because the provisioner results are at the // same level as all the other fields because... hacks JsonObject jsonObj = shallowCopy(json.getAsJsonObject()); Provider provider = context.deserialize(jsonObj.remove("provider"), Provider.class); Map<String, NodeProperties> nodePropertiesMap = context.deserialize(jsonObj.remove("nodes"), new TypeToken<Map<String, NodeProperties>>() { }.getType());//from w w w . j a v a 2 s. c om JsonObject clusterConfig = jsonObj.remove("cluster").getAsJsonObject(); TaskServiceAction taskServiceAction = context.deserialize(jsonObj.remove("service"), TaskServiceAction.class); // build node properties String hostname = context.deserialize(jsonObj.remove("hostname"), String.class); String ipaddress = context.deserialize(jsonObj.remove("ipaddress"), String.class); String imagetype = context.deserialize(jsonObj.remove("imagetype"), String.class); String hardwaretype = context.deserialize(jsonObj.remove("hardwaretype"), String.class); String flavor = context.deserialize(jsonObj.remove("flavor"), String.class); String image = context.deserialize(jsonObj.remove("image"), String.class); String sshUser = context.deserialize(jsonObj.remove("ssh-user"), String.class); Integer nodeNum = context.deserialize(jsonObj.remove("nodenum"), Integer.class); Set<String> serviceNames = context.deserialize(jsonObj.remove("services"), new TypeToken<Set<String>>() { }.getType()); Set<String> automators = context.deserialize(jsonObj.remove("automators"), new TypeToken<Set<String>>() { }.getType()); NodeProperties nodeProperties = NodeProperties.builder().setHostname(hostname).setIpaddress(ipaddress) .setNodenum(nodeNum).setHardwaretype(hardwaretype).setImagetype(imagetype).setFlavor(flavor) .setImage(image).setSSHUser(sshUser).setAutomators(automators).setServiceNames(serviceNames) .build(); // what's left is the provisioner results return new TaskConfig(nodeProperties, provider, nodePropertiesMap, taskServiceAction, clusterConfig, jsonObj); }