List of usage examples for com.google.gson JsonObject getAsJsonObject
public JsonObject getAsJsonObject(String memberName)
From source file:club.jmint.crossing.specs.ParamBuilder.java
License:Apache License
public static JsonObject getParams(String jsonParams) throws CrossException { JsonParser jp = new JsonParser(); JsonObject jo; try {/* w w w. j a v a2 s . c o m*/ jo = (JsonObject) jp.parse(jsonParams); } catch (JsonSyntaxException e) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } if (jo.has("params")) { return jo.getAsJsonObject("params"); } else { return null; } }
From source file:club.jmint.crossing.specs.ParamBuilder.java
License:Apache License
public static String checkSignAndRemove(String p, String signKey) throws CrossException { JsonParser jp = new JsonParser(); JsonElement jop = null;/*from ww w.j av a 2 s . com*/ try { jop = jp.parse(p); if (!jop.isJsonObject()) { throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } } catch (JsonSyntaxException jse) { //jse.printStackTrace(); throw new CrossException(ErrorCode.COMMON_ERR_PARAM_MALFORMED.getCode(), ErrorCode.COMMON_ERR_PARAM_MALFORMED.getInfo()); } JsonObject jo = (JsonObject) jop; String np = null; if (jo.has("sign") || jo.has("params")) { String sign = jo.getAsJsonPrimitive("sign").getAsString(); np = jo.getAsJsonObject("params").toString(); String signValue = Security.crossingSign(np, signKey, ""); if (!sign.equals(signValue)) { throw new CrossException(ErrorCode.COMMON_ERR_SIGN_BAD.getCode(), ErrorCode.COMMON_ERR_SIGN_BAD.getInfo()); } //remove sign field only and return Iterator<Entry<String, JsonElement>> it = jo.entrySet().iterator(); JsonObject rjo = new JsonObject(); Entry<String, JsonElement> en; while (it.hasNext()) { en = it.next(); if (!en.getKey().equals("sign")) { rjo.add(en.getKey(), en.getValue()); } } return rjo.toString(); } return p; }
From source file:co.cask.cdap.logging.gateway.handlers.LogDataOffsetCallback.java
License:Apache License
private Object modifyLogJsonElememnt(JsonElement jsonElement) { JsonObject jsonLogData = (JsonObject) jsonElement; JsonObject logData = jsonLogData.getAsJsonObject("log"); if (!fieldsToSuppress.isEmpty()) { for (String field : fieldsToSuppress) { logData.remove(field);/*from w ww. j a v a 2s . c om*/ } } return jsonLogData; }
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 . ja va 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.NamespacedIdCodec.java
License:Apache License
@Override public Id.NamespacedId deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); JsonObject id = jsonObj.getAsJsonObject("id"); String type = jsonObj.get("type").getAsString(); switch (type) { case "application": return deserializeApplicationId(id); case "program": return deserializeProgramId(id); case "flow": return deserializeFlowId(id); case "flowlet": return deserializeFlowletId(id); case "service": return deserializeServiceId(id); case "schedule": return deserializeSchedule(id); case "worker": return deserializeWorkerId(id); case "workflow": return deserializeWorkflowId(id); case "datasetinstance": return deserializeDatasetInstanceId(id); case "stream": return deserializeStreamId(id); case "view": return deserializeViewId(id); case "artifact": return deserializeArtifactId(id); default://w ww . j a v a 2 s. co m throw new UnsupportedOperationException(String.format( "Unsupported object of type %s found. Deserialization of only %s, %s, %s, %s, %s, %s, %s, " + "%s, %s, %s, %s, %s is supported.", type, Id.Application.class.getSimpleName(), Id.Program.class.getSimpleName(), Id.Flow.class.getSimpleName(), Id.Flow.Flowlet.class.getSimpleName(), Id.Service.class.getSimpleName(), Id.Schedule.class.getSimpleName(), Id.Worker.class.getSimpleName(), Id.Workflow.class.getSimpleName(), Id.DatasetInstance.class.getSimpleName(), Id.Stream.class.getSimpleName(), Id.Stream.View.class.getSimpleName(), Id.Artifact.class.getSimpleName())); } }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
private Id.Namespace deserializeNamespace(JsonObject id) { String namespace = id.getAsJsonObject("namespace").get("id").getAsString(); return Id.Namespace.from(namespace); }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
private Id.Program deserializeProgramId(JsonObject id) { Id.Application app = deserializeApplicationId(id.getAsJsonObject("application")); ProgramType programType = ProgramType.valueOf(id.get("type").getAsString().toUpperCase()); String programId = id.get("id").getAsString(); return Id.Program.from(app, programType, programId); }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
private Id.Flow.Flowlet deserializeFlowletId(JsonObject id) { Id.Flow flow = deserializeFlowId(id.getAsJsonObject("flow")); String flowletId = id.get("id").getAsString(); return Id.Flow.Flowlet.from(flow, flowletId); }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
private Id.Schedule deserializeSchedule(JsonObject id) { Id.Application app = deserializeApplicationId(id.getAsJsonObject("application")); String scheduleId = id.get("id").getAsString(); return Id.Schedule.from(app, scheduleId); }
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
private Id.Stream.View deserializeViewId(JsonObject id) { Id.Stream streamId = deserializeStreamId(id.getAsJsonObject("stream")); String view = id.get("id").getAsString(); return Id.Stream.View.from(streamId, view); }