List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:com.contentful.java.cda.ResourceTypeAdapter.java
License:Apache License
/** * Sets the base fields for a resource./*from w ww . j av a2s. com*/ * This will set the list fields based on the target's type, depending on whether * it is an instance of the {@code ResourceWithMap} class or the {@code ResourceWithList}, * different results will be provided. * * This method will also set the map of system attributes for the resource. * * @param target Target {@link CDAResource} object to set fields for. * @param sys JsonObject representing the system attributes of the resource in JSON form. * @param jsonElement JsonElement representing the resource in JSON form. * @param context De-serialization context. * @throws JsonParseException on failure. */ @SuppressWarnings("unchecked") private void setBaseFields(CDAResource target, JsonObject sys, JsonElement jsonElement, JsonDeserializationContext context) { CDASpace space = spaceWrapper.get(); // System attributes Map<String, Object> sysMap = context.deserialize(sys, Map.class); if (sysMap.containsKey("space")) { sysMap.put("space", space); } target.setSys(sysMap); // Fields JsonElement fields = jsonElement.getAsJsonObject().get("fields"); if (target instanceof ResourceWithMap) { ResourceWithMap res = (ResourceWithMap) target; target.setLocale(space.getDefaultLocale()); res.setRawFields(context.<Map<String, Object>>deserialize(fields.getAsJsonObject(), Map.class)); res.getLocalizedFieldsMap().put(space.getDefaultLocale(), res.getRawFields()); } else if (target instanceof ResourceWithList) { ResourceWithList<Object> res = (ResourceWithList<Object>) target; res.setFields(context.<List<Object>>deserialize(fields.getAsJsonArray(), List.class)); } }
From source file:com.continuuity.loom.codec.json.current.AddServicesRequestCodec.java
License:Apache License
@Override public AddServicesRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType());// ww w. ja v a 2s . c o m return new AddServicesRequest(services); }
From source file:com.continuuity.loom.codec.json.current.AdministrationCodec.java
License:Apache License
@Override public Administration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); LeaseDuration leaseDuration = context.deserialize(jsonObj.get("leaseduration"), LeaseDuration.class); return new Administration(leaseDuration); }
From source file:com.continuuity.loom.codec.json.current.AutomatorTypeCodec.java
License:Apache License
@Override public AutomatorType 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 www . j av a 2 s .c o m Map<String, ResourceTypeSpecification> resourceTypes = context.deserialize(jsonObj.get("resourceTypes"), new TypeToken<Map<String, ResourceTypeSpecification>>() { }.getType()); return new AutomatorType(name, description, parameters, resourceTypes); }
From source file:com.continuuity.loom.codec.json.current.ClusterCodec.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 w w w . j ava 2 s.co m*/ Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType()); String latestJobId = context.deserialize(jsonObj.get("latestJobId"), String.class); Account account = context.deserialize(jsonObj.get("account"), Account.class); Cluster.Status status = context.deserialize(jsonObj.get("status"), Cluster.Status.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); 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.current.ClusterConfigureRequestCodec.java
License:Apache License
@Override public ClusterConfigureRequest deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Boolean restart = context.deserialize(jsonObj.get("restart"), Boolean.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); return new ClusterConfigureRequest(config, restart); }
From source file:com.continuuity.loom.codec.json.current.ClusterCreateRequestCodec.java
License:Apache License
@Override public ClusterCreateRequest 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 clusterTemplate = context.deserialize(jsonObj.get("clusterTemplate"), String.class); Integer numMachines = context.deserialize(jsonObj.get("numMachines"), Integer.class); String provider = context.deserialize(jsonObj.get("provider"), String.class); Map<String, String> providerFields = context.deserialize(jsonObj.get("providerFields"), new TypeToken<Map<String, String>>() { }.getType());//from ww w . ja va 2 s. com Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType()); String hardwaretype = context.deserialize(jsonObj.get("hardwaretype"), String.class); String imagetype = context.deserialize(jsonObj.get("imagetype"), String.class); Long initialLeaseDuration = context.deserialize(jsonObj.get("initialLeaseDuration"), Long.class); String dnsSuffix = context.deserialize(jsonObj.get("dnsSuffix"), String.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); return new ClusterCreateRequest(name, description, clusterTemplate, numMachines, provider, providerFields, services, hardwaretype, imagetype, initialLeaseDuration, dnsSuffix, config); }
From source file:com.continuuity.loom.codec.json.current.ClusterDefaultsCodec.java
License:Apache License
@Override public ClusterDefaults deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType());//from w ww. jav a2s.c o m String provider = context.deserialize(jsonObj.get("provider"), String.class); String hardwaretype = context.deserialize(jsonObj.get("hardwaretype"), String.class); String imagetype = context.deserialize(jsonObj.get("imagetype"), String.class); String dnsSuffix = context.deserialize(jsonObj.get("dnsSuffix"), String.class); JsonObject config = context.deserialize(jsonObj.get("config"), JsonObject.class); return new ClusterDefaults(services, provider, hardwaretype, imagetype, dnsSuffix, config); }
From source file:com.continuuity.loom.codec.json.current.ClusterTemplateCodec.java
License:Apache License
@Override public ClusterTemplate 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); ClusterDefaults defaults = context.deserialize(jsonObj.get("defaults"), ClusterDefaults.class); Compatibilities compatibilites = context.deserialize(jsonObj.get("compatibility"), Compatibilities.class); Constraints constraints = context.deserialize(jsonObj.get("constraints"), Constraints.class); Administration administration = context.deserialize(jsonObj.get("administration"), Administration.class); return new ClusterTemplate(name, description, defaults, compatibilites, constraints, administration); }
From source file:com.continuuity.loom.codec.json.current.CompatibilitiesCodec.java
License:Apache License
@Override public Compatibilities deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); Set<String> hardwaretypes = context.deserialize(jsonObj.get("hardwaretypes"), new TypeToken<Set<String>>() { }.getType());/*from www . j a v a 2 s . co m*/ Set<String> imagetypes = context.deserialize(jsonObj.get("imagetypes"), new TypeToken<Set<String>>() { }.getType()); Set<String> services = context.deserialize(jsonObj.get("services"), new TypeToken<Set<String>>() { }.getType()); return new Compatibilities(hardwaretypes, imagetypes, services); }