List of usage examples for javax.json JsonObject toString
@Override String toString();
From source file:org.grogshop.services.endpoints.impl.ShopItemsServiceImpl.java
@Override public Response get(@PathParam("id") Long item_id) throws ServiceException { Item i = itemsService.getById(item_id); JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString()) .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString()) .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail()) .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString()) .add("type", (i.getType() == null) ? "" : i.getType().toString()) .add("name", (i.getName() == null) ? "" : i.getName()) .add("description", (i.getDescription() == null) ? "" : i.getDescription()) .add("hasImage", i.hasImage()) .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString()) .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString()); if (i.getTags() != null) { JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder(); for (String s : i.getTags()) { jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s)); }//from ww w . j ava 2 s . c om jsonObjectBuilder.add("tags", jsonArrayBuilderInterest); } JsonObject build = jsonObjectBuilder.build(); return Response.ok(build.toString()).build(); }
From source file:uk.theretiredprogrammer.nbpcglibrary.remoteclient.RemotePersistenceUnitProvider.java
/** * Execute Single Command - send a single command to executed by remote data * source./* w w w . j a v a2 s . c o m*/ * * @param tablename the name of the table to be accessed * @param action the action request on that table * @param request the command object * @return the response object * @throws IOException if problems with parsing command data or problems * executing the command */ public synchronized JsonObject executeSingleCommand(String tablename, String action, JsonObject request) throws IOException { JsonStructure res = null; HttpPost httpPost = new HttpPost(url + tablename + "/" + action); httpPost.setEntity(new StringEntity(request.toString(), APPLICATION_JSON)); try (CloseableHttpResponse response = httpclient.execute(httpPost)) { if (response.getStatusLine().getStatusCode() == 200) { HttpEntity responsebody = response.getEntity(); try (JsonReader jsonReader = Json.createReader(responsebody.getContent())) { res = jsonReader.read(); } EntityUtils.consume(responsebody); } } if (res instanceof JsonObject) { return (JsonObject) res; } else { throw new JsonConversionException(); } }
From source file:httputils.RavelloHttpClient.java
public HttpResponse post(String path, JsonObject body) throws IOException { HttpPost req = new HttpPost(HOMEADD + path); HttpUtil.setJsonHeaders(req);// w w w .j a v a 2 s. com req.setEntity(new StringEntity(body.toString())); return this.execute(req); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkStringField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); Settings settings = new Settings(); settings.setEntityClass(Person.class); Person person = (Person) aggregateService.create(jsonBuilder.build(), settings); assert (person.getId() != null); assert (person.getName().equals("DILIP_DALTON")); Object jsonObject = aggregateService.read(person, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkIntField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("employeeNo", 235); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getEmployeeNo() == 235); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("employeeNo")).intValue() == 235); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkLongField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("salary", 100000); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getSalary() == 100000); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("salary")).intValue() == 100000); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkEmptyLongField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getSalary() == null); assert (!employee.getIsCriticalSystemObject()); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (!json.containsKey("salary")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkBooleanField() throws JSONException { // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("isCriticalSystemObject", true); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getIsCriticalSystemObject()); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (json.getBoolean("isCriticalSystemObject")); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkBigDecimalField() throws JSONException { final BigDecimal largeDecimal = new BigDecimal("12345678998765432100000.123456789987654321"); // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("largeDecimal", largeDecimal); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getLargeDecimal().equals(largeDecimal)); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("largeDecimal")).bigDecimalValue().equals(largeDecimal)); }
From source file:tools.xor.logic.DefaultJson.java
protected void checkBigIntegerField() throws JSONException { final BigInteger largeInteger = new BigInteger("12345678998765432100000123456789987654321"); // create person JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); jsonBuilder.add("name", "DILIP_DALTON"); jsonBuilder.add("displayName", "Dilip Dalton"); jsonBuilder.add("description", "Software engineer in the bay area"); jsonBuilder.add("userName", "daltond"); jsonBuilder.add("largeInteger", largeInteger); Settings settings = new Settings(); settings.setEntityClass(Employee.class); Employee employee = (Employee) aggregateService.create(jsonBuilder.build(), settings); assert (employee.getId() != null); assert (employee.getName().equals("DILIP_DALTON")); assert (employee.getLargeInteger().equals(largeInteger)); Object jsonObject = aggregateService.read(employee, settings); JsonObject json = (JsonObject) jsonObject; System.out.println("JSON string: " + json.toString()); assert (((JsonString) json.get("name")).getString().equals("DILIP_DALTON")); assert (((JsonNumber) json.get("largeInteger")).bigIntegerValue().equals(largeInteger)); }