List of usage examples for com.google.gson JsonObject add
public void add(String property, JsonElement value)
From source file:co.cask.cdap.proto.codec.NamespacedIdCodec.java
License:Apache License
@Override public JsonElement serialize(Id.NamespacedId src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("type", new JsonPrimitive(src.getIdType())); jsonObj.add("id", context.serialize(src)); return jsonObj; }
From source file:co.cask.cdap.proto.codec.ScheduleSpecificationCodec.java
License:Apache License
@SuppressWarnings("deprecation") @Override//from ww w . j av a2 s . c o m public JsonElement serialize(ScheduleSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); ScheduleType scheduleType = ScheduleType.fromSchedule(src.getSchedule()); if (scheduleType.equals(ScheduleType.TIME)) { jsonObj.add("scheduleType", context.serialize(ScheduleType.TIME, ScheduleType.class)); jsonObj.add("schedule", context.serialize(src.getSchedule(), TimeSchedule.class)); } else if (scheduleType.equals(ScheduleType.STREAM)) { jsonObj.add("scheduleType", context.serialize(ScheduleType.STREAM, ScheduleType.class)); jsonObj.add("schedule", context.serialize(src.getSchedule(), StreamSizeSchedule.class)); } jsonObj.add("program", context.serialize(src.getProgram(), ScheduleProgramInfo.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); return jsonObj; }
From source file:co.cask.cdap.proto.codec.SparkSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(SparkSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("mainClassName", new JsonPrimitive(src.getMainClassName())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); if (src.getDriverResources() != null) { jsonObj.add("driverResources", context.serialize(src.getDriverResources())); }//from w w w . j a v a2s . c o m if (src.getExecutorResources() != null) { jsonObj.add("executorResources", context.serialize(src.getExecutorResources())); } return jsonObj; }
From source file:co.cask.cdap.proto.codec.WorkerSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(WorkerSpecification spec, Type typeOfSrc, JsonSerializationContext context) { JsonObject object = new JsonObject(); object.addProperty("className", spec.getClassName()); object.addProperty("name", spec.getName()); object.addProperty("description", spec.getDescription()); object.add("properties", serializeMap(spec.getProperties(), context, String.class)); object.add("resources", context.serialize(spec.getResources(), Resources.class)); object.add("datasets", serializeSet(spec.getDatasets(), context, String.class)); object.addProperty("instances", spec.getInstances()); return object; }
From source file:co.cask.cdap.proto.codec.WorkflowActionSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowActionSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("datasets", serializeSet(src.getDatasets(), context, String.class)); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); return jsonObj; }
From source file:co.cask.cdap.proto.codec.WorkflowNodeThrowableCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowNodeThrowable src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.addProperty("className", src.getClassName()); json.addProperty("message", src.getMessage()); json.add("stackTraces", context.serialize(src.getStackTraces(), StackTraceElement[].class)); json.add("cause", context.serialize(src.getCause(), WorkflowNodeThrowable.class)); return json;// w w w .j a v a 2s. c o m }
From source file:co.cask.cdap.proto.codec.WorkflowSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(WorkflowSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); jsonObj.add("nodes", serializeList(src.getNodes(), context, WorkflowNode.class)); jsonObj.add("localDatasetSpecs", serializeMap(src.getLocalDatasetSpecs(), context, DatasetCreationSpec.class)); return jsonObj; }
From source file:co.cask.cdap.template.etl.common.StructuredRecordSerializer.java
License:Apache License
@Override public JsonElement serialize(StructuredRecord src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); for (Schema.Field field : src.getSchema().getFields()) { obj.add(field.getName(), context.serialize(src.get(field.getName()))); }// w ww .j a v a 2 s . c o m return obj; }
From source file:co.cask.tigon.internal.app.FlowletSpecificationCodec.java
License:Apache License
@Override public JsonElement serialize(FlowletSpecification src, Type typeOfSrc, JsonSerializationContext context) { JsonObject jsonObj = new JsonObject(); jsonObj.add("className", new JsonPrimitive(src.getClassName())); jsonObj.add("name", new JsonPrimitive(src.getName())); jsonObj.add("description", new JsonPrimitive(src.getDescription())); jsonObj.add("failurePolicy", new JsonPrimitive(src.getFailurePolicy().name())); jsonObj.add("properties", serializeMap(src.getProperties(), context, String.class)); jsonObj.add("resources", context.serialize(src.getResources(), new TypeToken<ResourceSpecification>() { }.getType()));/*from w w w.ja v a2 s . c om*/ jsonObj.add("maxInstances", new JsonPrimitive(src.getMaxInstances())); return jsonObj; }
From source file:co.com.konrad.interbolsa.ws.AccionesFacadeREST.java
@POST @Override/*ww w. ja v a2 s .c om*/ @Path("create") @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public String create(Acciones entity) throws Exception { //VAriable json JsonObject res = new JsonObject(); Gson gson = new Gson(); try { //retorno res.addProperty("codigo", 200); res.addProperty("mensaje", "operacion exitosa"); super.create(entity); javax.persistence.criteria.CriteriaBuilder cb = getEntityManager().getCriteriaBuilder(); javax.persistence.criteria.CriteriaQuery cq = cb.createQuery(); javax.persistence.criteria.Root<Acciones> rt = cq.from(Acciones.class); /*cq.where( cb.equal(rt.get(Empresa_.empresaNit), entity.getEmpresaNit()) );*/ javax.persistence.TypedQuery<Acciones> q = getEntityManager().createQuery(cq); Acciones acciones = q.getSingleResult(); res.add("data", gson.toJsonTree(acciones)); } catch (Exception ex) { java.util.logging.Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE, "Erro guardando entidad", ex); res.addProperty("codigo", 400); res.addProperty("mensaje", "operacion fallida"); } //return res.toString(); return "{'hola':1}"; }