Example usage for com.google.gson JsonElement getAsJsonObject

List of usage examples for com.google.gson JsonElement getAsJsonObject

Introduction

In this page you can find the example usage for com.google.gson JsonElement getAsJsonObject.

Prototype

public JsonObject getAsJsonObject() 

Source Link

Document

convenience method to get this element as a JsonObject .

Usage

From source file:com.continuuity.loom.codec.json.current.HardwareTypeCodec.java

License:Apache License

@Override
public HardwareType 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<String, Map<String, String>> providerMap = context.deserialize(jsonObj.get("providermap"),
            new TypeToken<Map<String, Map<String, String>>>() {
            }.getType());// w  w w  . j  ava  2  s. c o m

    return new HardwareType(name, description, providerMap);
}

From source file:com.continuuity.loom.codec.json.current.ImageTypeCodec.java

License:Apache License

@Override
public ImageType 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<String, Map<String, String>> providerMap = context.deserialize(jsonObj.get("providermap"),
            new TypeToken<Map<String, Map<String, String>>>() {
            }.getType());/*from  w  ww . ja v a  2  s  . c  om*/

    return new ImageType(name, description, providerMap);
}

From source file:com.continuuity.loom.codec.json.current.LayoutConstraintCodec.java

License:Apache License

@Override
public LayoutConstraint deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    Set<Set<String>> servicesThatMustCoexist = context.deserialize(jsonObj.get("mustcoexist"),
            new TypeToken<Set<Set<String>>>() {
            }.getType());//  w w  w.j a va2  s  . com
    Set<Set<String>> servicesThatMustNotCoexist = context.deserialize(jsonObj.get("cantcoexist"),
            new TypeToken<Set<Set<String>>>() {
            }.getType());

    return new LayoutConstraint(servicesThatMustCoexist, servicesThatMustNotCoexist);
}

From source file:com.continuuity.loom.codec.json.current.LeaseDurationCodec.java

License:Apache License

@Override
public LeaseDuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    Long initial = context.deserialize(jsonObj.get("initial"), Long.class);
    Long max = context.deserialize(jsonObj.get("max"), Long.class);
    Long step = context.deserialize(jsonObj.get("step"), Long.class);

    return new LeaseDuration(initial, max, step);
}

From source file:com.continuuity.loom.codec.json.current.ParametersSpecificationCodec.java

License:Apache License

@Override
public ParametersSpecification deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    Map<String, FieldSchema> fields = context.deserialize(jsonObj.get("fields"),
            new TypeToken<Map<String, FieldSchema>>() {
            }.getType());/*from ww w  .  j  a  v a  2 s.c  o  m*/
    Set<Set<String>> required = context.deserialize(jsonObj.get("required"), new TypeToken<Set<Set<String>>>() {
    }.getType());

    return new ParametersSpecification(fields, required);
}

From source file:com.continuuity.loom.codec.json.current.PluginResourceMetaCodec.java

License:Apache License

@Override
public ResourceMeta deserialize(JsonElement json, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject jsonObj = json.getAsJsonObject();

    String name = context.deserialize(jsonObj.get("name"), String.class);
    Integer version = context.deserialize(jsonObj.get("version"), Integer.class);
    ResourceStatus status = context.deserialize(jsonObj.get("status"), ResourceStatus.class);

    return new ResourceMeta(name, version, status);
}

From source file:com.continuuity.loom.codec.json.current.ProviderCodec.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 = context.deserialize(jsonObj.get("provisioner"),
            new TypeToken<Map<String, String>>() {
            }.getType());//w  ww .j a v  a  2  s  . c o m

    return new Provider(name, description, providerType, provisionerFields);
}

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 ww w. j  a  v a  2  s.  c om*/
    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());/*w w w  .  java 2 s  . c  o  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);
}