Example usage for com.google.gson JsonObject get

List of usage examples for com.google.gson JsonObject get

Introduction

In this page you can find the example usage for com.google.gson JsonObject get.

Prototype

public JsonElement get(String memberName) 

Source Link

Document

Returns the member with the specified name.

Usage

From source file:co.cask.cdap.etl.spark.batch.DatasetInfoTypeAdapter.java

License:Apache License

@Override
public DatasetInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject obj = json.getAsJsonObject();
    String datasetName = obj.get("datasetName").getAsString();
    Map<String, String> datasetArgs = context.deserialize(obj.get("datasetArgs"), mapType);
    if (obj.get("datasetSplitClass") == null) {
        return new DatasetInfo(datasetName, datasetArgs, null);
    }/*from   w  w  w  . j a va2s  . c  o  m*/
    String datasetSplitClass = obj.get("datasetSplitClass").getAsString();
    ClassLoader classLoader = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(),
            SparkBatchSourceFactory.class.getClassLoader());
    try {
        Class<?> splitClass = classLoader.loadClass(datasetSplitClass);
        List<Split> splits = context.deserialize(obj.get("datasetSplits"), getListType(splitClass));
        return new DatasetInfo(datasetName, datasetArgs, splits);
    } catch (ClassNotFoundException e) {
        throw new JsonParseException("Unable to deserialize splits", e);
    }
}

From source file:co.cask.cdap.etl.spark.batch.InputFormatProviderTypeAdapter.java

License:Apache License

@Override
public InputFormatProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject obj = json.getAsJsonObject();
    // if inputFormat is not present, return empty InputFormatProvider
    if (obj.get("inputFormatClass") == null) {
        return new SparkBatchSourceFactory.BasicInputFormatProvider();
    }//from w w w  .j  av  a2 s. c  o  m
    String className = obj.get("inputFormatClass").getAsString();
    Map<String, String> conf = context.deserialize(obj.get("inputFormatConfig"), mapType);
    return new SparkBatchSourceFactory.BasicInputFormatProvider(className, conf);
}

From source file:co.cask.cdap.etl.spark.batch.OutputFormatProviderTypeAdapter.java

License:Apache License

@Override
public OutputFormatProvider deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    JsonObject obj = json.getAsJsonObject();
    // if outputformat is not present, return empty OutputFormatProvider
    if (obj.get("outputFormatClass") == null) {
        return new SparkBatchSinkFactory.BasicOutputFormatProvider();
    }/*from  w  w  w . java 2  s .c  o  m*/
    String className = obj.get("outputFormatClass").getAsString();
    Map<String, String> conf = context.deserialize(obj.get("outputFormatConfig"), mapType);
    return new SparkBatchSinkFactory.BasicOutputFormatProvider(className, conf);
}

From source file:co.cask.cdap.gateway.GatewayTestBase.java

License:Apache License

protected static String getState(String programType, String appId, String programId) throws Exception {
    HttpResponse response = GatewayFastTestsSuite
            .doGet(String.format("/v3/namespaces/default/apps/%s/%s/%s/status", appId, programType, programId));
    JsonObject status = GSON.fromJson(EntityUtils.toString(response.getEntity()), JsonObject.class);
    if (status != null && status.has("status")) {
        return status.get("status").getAsString();
    }/*from   ww  w  .  j a  va  2s.co  m*/
    return null;
}

From source file:co.cask.cdap.internal.app.ApplicationSpecificationCodec.java

License:Apache License

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

    String name = jsonObj.get("name").getAsString();

    String description = jsonObj.get("description").getAsString();
    String configuration = null;//from w ww. j a  v a  2  s  .  c  o m
    if (jsonObj.has("configuration")) {
        configuration = jsonObj.get("configuration").getAsString();
    }

    ArtifactId artifactId = context.deserialize(jsonObj.get("artifactId"), ArtifactId.class);

    Map<String, StreamSpecification> streams = deserializeMap(jsonObj.get("streams"), context,
            StreamSpecification.class);
    Map<String, String> datasetModules = deserializeMap(jsonObj.get("datasetModules"), context, String.class);
    Map<String, DatasetCreationSpec> datasetInstances = deserializeMap(jsonObj.get("datasetInstances"), context,
            DatasetCreationSpec.class);
    Map<String, FlowSpecification> flows = deserializeMap(jsonObj.get("flows"), context,
            FlowSpecification.class);
    Map<String, MapReduceSpecification> mapReduces = deserializeMap(jsonObj.get("mapReduces"), context,
            MapReduceSpecification.class);
    Map<String, SparkSpecification> sparks = deserializeMap(jsonObj.get("sparks"), context,
            SparkSpecification.class);
    Map<String, WorkflowSpecification> workflows = deserializeMap(jsonObj.get("workflows"), context,
            WorkflowSpecification.class);

    Map<String, ServiceSpecification> services = deserializeMap(jsonObj.get("services"), context,
            ServiceSpecification.class);

    Map<String, ScheduleSpecification> schedules = deserializeMap(jsonObj.get("schedules"), context,
            ScheduleSpecification.class);

    Map<String, WorkerSpecification> workers = deserializeMap(jsonObj.get("workers"), context,
            WorkerSpecification.class);
    Map<String, Plugin> plugins = deserializeMap(jsonObj.get("plugins"), context, Plugin.class);

    return new DefaultApplicationSpecification(name, description, configuration, artifactId, streams,
            datasetModules, datasetInstances, flows, mapReduces, sparks, workflows, services, schedules,
            workers, plugins);
}

From source file:co.cask.cdap.internal.app.FlowletSpecificationCodec.java

License:Apache License

@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());
    Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    ResourceSpecification resources = context.deserialize(jsonObj.get("resources"),
            new TypeToken<ResourceSpecification>() {
            }.getType());/*  w ww.ja va2  s.c om*/

    return new DefaultFlowletSpecification(className, name, description, policy, dataSets, properties,
            resources);
}

From source file:co.cask.cdap.internal.app.FlowSpecificationCodec.java

License:Apache License

@Override
public FlowSpecification 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();
    Map<String, FlowletDefinition> flowlets = deserializeMap(jsonObj.get("flowlets"), context,
            FlowletDefinition.class);
    List<FlowletConnection> connections = deserializeList(jsonObj.get("connections"), context,
            FlowletConnection.class);

    return new DefaultFlowSpecification(className, name, description, flowlets, connections);
}

From source file:co.cask.cdap.internal.app.MapReduceSpecificationCodec.java

License:Apache License

@Override
public MapReduceSpecification 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();
    int mapperMemoryMB = jsonObj.get("mapperMemoryMB").getAsInt();
    int reducerMemoryMB = jsonObj.get("reducerMemoryMB").getAsInt();
    JsonElement inputDataSetElem = jsonObj.get("inputDataSet");
    String inputDataSet = inputDataSetElem == null ? null : inputDataSetElem.getAsString();
    JsonElement outputDataSetElem = jsonObj.get("outputDataSet");
    String outputDataSet = outputDataSetElem == null ? null : outputDataSetElem.getAsString();

    Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);

    return new DefaultMapReduceSpecification(className, name, description, inputDataSet, outputDataSet,
            dataSets, properties, mapperMemoryMB, reducerMemoryMB);
}

From source file:co.cask.cdap.internal.app.ProcedureSpecificationCodec.java

License:Apache License

@Override
public ProcedureSpecification 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();
    Set<String> dataSets = deserializeSet(jsonObj.get("datasets"), context, String.class);
    Map<String, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class);
    ResourceSpecification resourceSpec = context.deserialize(jsonObj.get("resources"),
            new TypeToken<ResourceSpecification>() {
            }.getType());/*  w w w .j a v a  2s .  c  o  m*/

    JsonElement instanceElem = jsonObj.get("instances");
    int instances = (instanceElem == null || instanceElem.isJsonNull()) ? 1
            : jsonObj.get("instances").getAsInt();
    return new DefaultProcedureSpecification(className, name, description, dataSets, properties, resourceSpec,
            instances);
}

From source file:co.cask.cdap.internal.app.ResourceSpecificationCodec.java

License:Apache License

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

    int cores = jsonObj.get("virtualCores").getAsInt();
    int memorySize = jsonObj.get("memoryMB").getAsInt();

    return new Resources(memorySize, cores);
}