List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:azkaban.web.pages.JobDetailServlet.java
@SuppressWarnings("unchecked") private String getJSONText(Props prop) { JSONObject jsonObj = new JSONObject(); for (String key : prop.localKeySet()) { Object value = prop.get(key); jsonObj.put(key, value);// w w w .j a va2 s.c o m } return jsonObj.toJSONString(); }
From source file:com.aerothai.database.devicetype.DeviceTypeResource.java
/** * Retrieves representation of an instance of com.aerothai.DeviceTypeResource * @return an instance of java.lang.String *///from w w w .j a v a 2 s .c o m @GET @Produces("application/json") public String listDeviceTypeAt(@PathParam("id") int id) { String response = null; System.out.println("List DeviceType At ID"); try { JSONObject deviceTypeData = null; DeviceTypeService deviceTypeService = new DeviceTypeService(); deviceTypeData = deviceTypeService.GetDeviceTypeAt(id); response = deviceTypeData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:com.conwet.silbops.msg.UnadvertiseMsgTest.java
@Test public void shouldDeserializeOptionalUncovered() throws ParseException { // this test covers the case clients are sending unsubscribe UnadvertiseMsg msg = new UnadvertiseMsg(); msg.setAdvertise(new Advertise().attribute("attr1", Type.STRING).attribute("attr2", Type.STRING) .attribute("attr3", Type.DOUBLE)); Advertise covered = new Advertise(); covered.attribute("attrCov", Type.DOUBLE); Set<Advertise> uncovered = new HashSet<>(); uncovered.add(covered);//from w w w . j ava2 s .com msg.setUncovered(uncovered); JSONObject jsonTmp = msg.toJSON(); // delete uncovered part ((JSONObject) jsonTmp.get("payload")).remove("uncovered"); uncovered.clear(); String jsonStr = jsonTmp.toJSONString(); JSONObject json = (JSONObject) new JSONParser().parse(jsonStr); UnadvertiseMsg newMsg = (UnadvertiseMsg) UnadvertiseMsg.fromJSON(json); assertThat(newMsg).isEqualTo(msg); assertThat(newMsg.getUncovered()).isEqualTo(uncovered); }
From source file:org.kitodo.data.elasticsearch.index.type.UserGroupType.java
@SuppressWarnings("unchecked") @Override/*from w ww . jav a 2s. c o m*/ public HttpEntity createDocument(UserGroup userGroup) { JSONObject userGroupObject = new JSONObject(); userGroupObject.put("title", userGroup.getTitle()); userGroupObject.put("permission", userGroup.getPermission()); userGroupObject.put("users", addObjectRelation(userGroup.getUsers())); return new NStringEntity(userGroupObject.toJSONString(), ContentType.APPLICATION_JSON); }
From source file:com.aerothai.database.servicetype.ServicetypeResource.java
/** * Retrieves representation of an instance of com.aerothai.ServicetypeResource * @return an instance of java.lang.String */// www . j a v a2 s .c o m @GET @Produces("application/json") public String listServicetypeAt(@PathParam("id") int id) { String response = null; System.out.println("List Servicetype At ID"); try { JSONObject servicetypeData = null; ServicetypeService servicetypeService = new ServicetypeService(); servicetypeData = servicetypeService.GetServicetypeAt(id); response = servicetypeData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:naftoreiclag.villagefive.world.entity.Entity.java
public final String toJSONString() { JSONObject obj = new JSONObject(); obj.put("instanceof", this.getEntityId()); obj.put("location", new Vec2(this.node.getLocalTranslation())); this.addAdditionalData(obj); return obj.toJSONString(); }
From source file:com.conwet.silbops.msg.UnsubscribeMsgTest.java
@Test public void shouldDeserializeOptionalUncovered() throws ParseException { // this test covers the case clients are sending unsubscribe UnsubscribeMsg msg = new UnsubscribeMsg(); msg.setSubscription(//w w w. ja v a2 s . c o m new Subscription().constrain("attr1", Type.STRING).exists().constrain("attr2", Type.STRING) .eq("hello").constrain("attr3", Type.DOUBLE).gt(10.3D).subscription()); Set<Subscription> uncovered = new HashSet<>(); uncovered.add(new Subscription().constrain("attr1", Type.STRING).exists().subscription()); msg.setUncovered(uncovered); JSONObject jsonTmp = msg.toJSON(); // delete uncovered part ((JSONObject) jsonTmp.get("payload")).remove("uncovered"); uncovered.clear(); String jsonStr = jsonTmp.toJSONString(); JSONObject json = (JSONObject) new JSONParser().parse(jsonStr); UnsubscribeMsg newMsg = (UnsubscribeMsg) UnsubscribeMsg.fromJSON(json); assertThat(newMsg).isEqualTo(msg); assertThat(newMsg.getUncovered()).isEqualTo(uncovered); }
From source file:com.pingidentity.adapters.idp.mobileid.restservice.MssSignatureRequestJson.java
private String buildRequestMessage() { JSONObject request = new JSONObject(); request.put("MSS_SignatureReq", buildSignatureRequest()); return request.toJSONString(); }
From source file:com.aerothai.database.jobevaluate.JobevaluateResource.java
/** * Retrieves representation of an instance of com.aerothai.JobevaluateResource * @return an instance of java.lang.String *//*from w w w . j a va2 s.c om*/ @GET @Produces("application/json") public String listJobevaluateAt(@PathParam("id") int id) { String response = null; System.out.println("List Jobevaluate At ID"); try { JSONObject jobevaluateData = null; JobevaluateService jobevaluateService = new JobevaluateService(); jobevaluateData = jobevaluateService.GetJobevaluateAt(id); response = jobevaluateData.toJSONString(); } catch (Exception e) { System.out.println("error"); } return response; }
From source file:at.uni_salzburg.cs.ckgroup.cscpp.engine.actions.Picture.java
@SuppressWarnings("unchecked") @Override/*from w w w .ja v a2 s . c o m*/ public String toJSONString() { JSONObject o = new JSONObject(); o.put("type", ISensorProxy.SENSOR_NAME_PHOTO); if (getTimestamp() != 0) { o.put("time", getTimestamp()); o.put("value", getFilename()); } return o.toJSONString(); }