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.TenantCodec.java
License:Apache License
@Override public Tenant deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); TenantSpecification specification = context.deserialize(jsonObj.get("specification"), TenantSpecification.class); return new Tenant(id, specification); }
From source file:com.continuuity.loom.codec.json.current.TenantSpecificationCodec.java
License:Apache License
@Override public TenantSpecification deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String name = context.deserialize(jsonObj.get("name"), String.class); Integer workers = context.deserialize(jsonObj.get("workers"), Integer.class); Integer maxClusters = context.deserialize(jsonObj.get("maxClusters"), Integer.class); Integer maxNodes = context.deserialize(jsonObj.get("maxNodes"), Integer.class); return new TenantSpecification(name, workers, maxClusters, maxNodes); }
From source file:com.continuuity.loom.codec.json.upgrade.ClusterUpgradeCodec.java
License:Apache License
@Override public Cluster deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); String name = context.deserialize(jsonObj.get("name"), String.class); String description = context.deserialize(jsonObj.get("description"), String.class); long createTime = jsonObj.get("createTime").getAsLong(); Long expireTime = context.deserialize(jsonObj.get("expireTime"), Long.class); Provider provider = context.deserialize(jsonObj.get("provider"), Provider.class); ClusterTemplate template = context.deserialize(jsonObj.get("clusterTemplate"), ClusterTemplate.class); Set<String> nodes = context.deserialize(jsonObj.get("nodes"), new TypeToken<Set<String>>() { }.getType());//from ww w. java 2 s.c o m Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType()); String latestJobId = context.deserialize(jsonObj.get("latestJobId"), String.class); Cluster.Status status = context.deserialize(jsonObj.get("status"), Cluster.Status.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); // 'jobs' got replaced by 'latestJobId' if (latestJobId == null) { List<String> jobIds = context.deserialize(jsonObj.get("jobs"), new TypeToken<List<String>>() { }.getType()); if (jobIds != null) { latestJobId = jobIds.get(jobIds.size() - 1); } } // owner id replaced with account String ownerId = context.deserialize(jsonObj.get("ownerId"), String.class); Account account = new Account(ownerId, tenant); return new Cluster(id, account, name, createTime, expireTime == null ? 0 : expireTime, description, provider, template, nodes, services, config, status, latestJobId); }
From source file:com.continuuity.loom.codec.json.upgrade.NodeUpgradeCodec.java
License:Apache License
@Override public Node deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String id = context.deserialize(jsonObj.get("id"), String.class); String clusterId = context.deserialize(jsonObj.get("clusterId"), String.class); Set<Service> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<Service>>() { }.getType());/*from ww w.j a v a 2s .c om*/ JsonObject properties = jsonObj.getAsJsonObject("properties"); String ipaddress = context.deserialize(properties.get("ipaddress"), String.class); String hostname = context.deserialize(properties.get("hostname"), String.class); Integer nodenum = context.deserialize(properties.get("nodenum"), Integer.class); if (nodenum == null) { nodenum = 0; } Set<String> automators = context.deserialize(properties.get("automators"), new TypeToken<Set<String>>() { }.getType()); Set<String> nodeServices = context.deserialize(properties.get("services"), new TypeToken<Set<String>>() { }.getType()); String hardwaretype = context.deserialize(properties.get("hardwaretype"), String.class); String imagetype = context.deserialize(properties.get("imagetype"), String.class); String flavor = context.deserialize(properties.get("flavor"), String.class); String image = context.deserialize(properties.get("image"), String.class); NodeProperties nodeProperties = NodeProperties.builder().setHostname(hostname).setIpaddress(ipaddress) .setNodenum(nodenum).setHardwaretype(hardwaretype).setImagetype(imagetype).setFlavor(flavor) .setImage(image).setAutomators(automators).setServiceNames(nodeServices).setSSHUser("root").build(); return new Node(id, clusterId, services, nodeProperties); }
From source file:com.continuuity.loom.codec.json.upgrade.ProviderUpgradeCodec.java
License:Apache License
@Override public Provider 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); String providerType = context.deserialize(jsonObj.get("providertype"), String.class); Map<String, String> provisionerFields = deserializeProvisionerFields(jsonObj, context); return new Provider(name, description, providerType, provisionerFields); }
From source file:com.continuuity.loom.codec.json.upgrade.ProviderUpgradeCodec.java
License:Apache License
private Map<String, String> deserializeProvisionerFields(JsonObject jsonObj, JsonDeserializationContext context) { if (!jsonObj.has("provisioner")) { return Maps.newHashMap(); }// w w w . j a v a 2 s.com JsonObject fields = jsonObj.get("provisioner").getAsJsonObject(); // if its the old type if (fields.has("auth")) { JsonElement authElement = fields.get("auth"); if (authElement.isJsonObject()) { fields = authElement.getAsJsonObject(); } } return context.deserialize(fields, new TypeToken<Map<String, String>>() { }.getType()); }
From source file:com.continuuity.loom.codec.json.upgrade.ServiceActionUpgradeCodec.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 w w w . j a va2 s. c o m*/ // For backwards compatibility. if (jsonObj.has("script")) { if (fields == null) { fields = Maps.newHashMap(); } fields.put("script", jsonObj.get("script").getAsString()); } if (jsonObj.has("data")) { if (fields == null) { fields = Maps.newHashMap(); } fields.put("data", jsonObj.get("data").getAsString()); } return new ServiceAction(actionType, fields); }
From source file:com.continuuity.loom.codec.json.upgrade.ServiceUpgradeCodec.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); Set<String> dependsOn = context.deserialize(jsonObj.get("dependson"), new TypeToken<Set<String>>() { }.getType());//from ww w.j a v a2 s .co m ServiceDependencies dependencies = context.deserialize(jsonObj.get("dependencies"), ServiceDependencies.class); // for backwards compatibility, "dependson" expanded to "dependencies" if (dependsOn != null && !dependsOn.isEmpty()) { if (dependencies == null) { dependencies = new ServiceDependencies(null, null, null, new ServiceStageDependencies(dependsOn, null)); } else if (dependencies.getRuntime().getRequires().isEmpty()) { dependencies = new ServiceDependencies(dependencies.getProvides(), dependencies.getConflicts(), dependencies.getInstall(), new ServiceStageDependencies(dependsOn, dependencies.getRuntime().getUses())); } } 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()); } return new Service(name, description, dependencies, actions); }
From source file:com.continuuity.weave.internal.json.ArgumentsCodec.java
License:Open Source License
@Override public Arguments deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); List<String> arguments = context.deserialize(jsonObj.get("arguments"), new TypeToken<List<String>>() { }.getType());//from w ww.j av a2 s . com Map<String, Collection<String>> args = context.deserialize(jsonObj.get("runnableArguments"), new TypeToken<Map<String, Collection<String>>>() { }.getType()); ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); for (Map.Entry<String, Collection<String>> entry : args.entrySet()) { builder.putAll(entry.getKey(), entry.getValue()); } return new Arguments(arguments, builder.build()); }
From source file:com.continuuity.weave.internal.json.ResourceReportCodec.java
License:Apache License
@Override public ResourceReport deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String appMasterId = jsonObj.get("appMasterId").getAsString(); WeaveRunResources masterResources = context.deserialize(jsonObj.get("appMasterResources"), WeaveRunResources.class); Map<String, Collection<WeaveRunResources>> resources = context.deserialize(jsonObj.get("runnableResources"), new TypeToken<Map<String, Collection<WeaveRunResources>>>() { }.getType());//from w ww . j a v a 2 s. c o m return new DefaultResourceReport(appMasterId, masterResources, resources); }