List of usage examples for com.google.gson JsonObject get
public JsonElement get(String memberName)
From source file:co.cask.cdap.passport.http.client.PassportClient.java
License:Apache License
/** * Get List of VPC for the apiKey.//from w ww .j ava2 s. c om * @return List of VPC Names */ public List<String> getVPCList(String apiKey) { Preconditions.checkNotNull(apiKey, "ApiKey cannot be null"); List<String> vpcList = Lists.newArrayList(); try { String data = responseCache.getIfPresent(apiKey); if (data == null) { data = httpGet(API_BASE + "vpc/list", apiKey); if (data != null) { responseCache.put(apiKey, data); } } if (data != null) { JsonParser parser = new JsonParser(); JsonElement element = parser.parse(data); JsonArray jsonArray = element.getAsJsonArray(); for (JsonElement elements : jsonArray) { JsonObject vpc = elements.getAsJsonObject(); if (vpc.get("vpc_name") != null) { vpcList.add(vpc.get("vpc_name").getAsString()); } } } } catch (Exception e) { throw Throwables.propagate(e); } return vpcList; }
From source file:co.cask.cdap.proto.codec.AuditMessageTypeAdapter.java
License:Apache License
@Override public AuditMessage deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); long timeMillis = jsonObj.get("time").getAsLong(); EntityId entityId = context.deserialize(jsonObj.getAsJsonObject("entityId"), EntityId.class); String user = jsonObj.get("user").getAsString(); AuditType auditType = context.deserialize(jsonObj.getAsJsonPrimitive("type"), AuditType.class); AuditPayload payload;/*from w w w .jav a 2 s . c o m*/ JsonObject jsonPayload = jsonObj.getAsJsonObject("payload"); switch (auditType) { case METADATA_CHANGE: payload = context.deserialize(jsonPayload, MetadataPayload.class); break; case ACCESS: payload = context.deserialize(jsonPayload, AccessPayload.class); break; default: payload = AuditPayload.EMPTY_PAYLOAD; } return new AuditMessage(timeMillis, entityId, user, auditType, payload); }
From source file:co.cask.cdap.proto.codec.BasicThrowableCodec.java
License:Apache License
@Override public BasicThrowable deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); String className = jsonObj.get("className").getAsString(); String message = jsonObj.get("message").getAsString(); JsonArray stackTraces = jsonObj.get("stackTraces").getAsJsonArray(); StackTraceElement[] stackTraceElements = context.deserialize(stackTraces, StackTraceElement[].class); JsonElement cause = jsonObj.get("cause"); BasicThrowable basicThrowable = null; if (cause != null) { basicThrowable = context.deserialize(cause, BasicThrowable.class); }//from ww w. ja va 2 s . co m return new BasicThrowable(className, message, stackTraceElements, basicThrowable); }
From source file:co.cask.cdap.proto.codec.CustomActionSpecificationCodec.java
License:Apache License
@Override public CustomActionSpecification 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); return new DefaultCustomActionSpecification(className, name, description, properties, datasets); }
From source file:co.cask.cdap.proto.codec.EntityIdTypeAdapter.java
License:Apache License
@Override public EntityId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject map = json.getAsJsonObject(); JsonElement entityTypeJson = map.get("entity"); if (entityTypeJson == null) { throw new JsonParseException("Expected entity in EntityId JSON"); }// w ww . j av a 2s. co m String entityTypeString = entityTypeJson.getAsString(); EntityType type = EntityType.valueOf(entityTypeString); if (type == null) { throw new JsonParseException("Invalid entity: " + entityTypeString); } return context.deserialize(json, type.getIdClass()); }
From source file:co.cask.cdap.proto.codec.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); Resources resources = context.deserialize(jsonObj.get("resources"), Resources.class); return new DefaultFlowletSpecification(className, name, description, policy, dataSets, properties, resources);/*from w w w .ja va 2 s . co m*/ }
From source file:co.cask.cdap.proto.codec.HttpServiceSpecificationCodec.java
License:Apache License
@Override public HttpServiceHandlerSpecification 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, String> properties = deserializeMap(jsonObj.get("properties"), context, String.class); Set<String> datasets = deserializeSet(jsonObj.get("datasets"), context, String.class); List<ServiceHttpEndpoint> endpointsExposed; if (isOldSpec(jsonObj)) { endpointsExposed = ImmutableList.of(); } else {/*from w ww . j a v a 2s. com*/ endpointsExposed = deserializeList(jsonObj.get("endpoints"), context, ServiceHttpEndpoint.class); } return new HttpServiceHandlerSpecification(className, name, description, properties, datasets, endpointsExposed); }
From source file:co.cask.cdap.proto.codec.IdTypeAdapter.java
License:Apache License
@Override public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject map = json.getAsJsonObject(); JsonElement elementTypeJson = map.get("elementType"); if (elementTypeJson == null) { throw new JsonParseException("Expected elementType in Id JSON"); }/*from w ww . j av a 2 s . co m*/ String elementTypeString = elementTypeJson.getAsString(); EntityType type = EntityType.valueOf(elementTypeString); if (type == null) { throw new JsonParseException("Invalid elementType: " + elementTypeString); } return context.deserialize(json, type.getIdClass()); }
From source file:co.cask.cdap.proto.codec.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(); Resources driverResources = deserializeResources(jsonObj, "driver", context); Resources mapperResources = deserializeResources(jsonObj, "mapper", context); Resources reducerResources = deserializeResources(jsonObj, "reducer", context); 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 MapReduceSpecification(className, name, description, inputDataSet, outputDataSet, dataSets, properties, driverResources, mapperResources, reducerResources); }
From source file:co.cask.cdap.proto.codec.MapReduceSpecificationCodec.java
License:Apache License
/** * Deserialize the resources field from the serialized object. * * @param jsonObj The object representing the MapReduceSpecification * @param prefix Field name prefix. Either "mapper" or "reducer" * @param context The context to deserialize object. * @return A {@link Resources} or {@code null}. *///from w ww . j a v a 2s . c o m private Resources deserializeResources(JsonObject jsonObj, String prefix, JsonDeserializationContext context) { // See if it of new format String name = prefix + "Resources"; JsonElement element = jsonObj.get(name); if (element != null) { return context.deserialize(element, Resources.class); } // Try the old format, which is an int field representing the memory in MB. name = prefix + "MemoryMB"; element = jsonObj.get(name); if (element != null) { return new Resources(element.getAsInt()); } return null; }