List of usage examples for javax.json JsonObjectBuilder add
JsonObjectBuilder add(String name, JsonArrayBuilder builder);
From source file:au.org.ands.vocabs.toolkit.provider.transform.SolrIndexTransformProvider.java
@Override public final boolean transform(final TaskInfo taskInfo, final JsonNode subtask, final HashMap<String, String> results) { Path dir = Paths.get(ToolkitFileUtils.getTaskHarvestOutputPath(taskInfo)); ConceptHandler conceptHandler = new ConceptHandler(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (Path entry : stream) { RDFFormat format = Rio.getParserFormatForFileName(entry.toString()); RDFParser rdfParser = Rio.createParser(format); rdfParser.setRDFHandler(conceptHandler); FileInputStream is = new FileInputStream(entry.toString()); rdfParser.parse(is, entry.toString()); logger.debug("Reading RDF:" + entry.toString()); }//from w ww . j a va2 s .c om } catch (DirectoryIteratorException | IOException | RDFParseException | RDFHandlerException ex) { // I/O error encountered during the iteration, // the cause is an IOException results.put(TaskStatus.EXCEPTION, "Exception in SolrIndexTransform while Parsing RDF"); logger.error("Exception in SolrIndexTransform while Parsing RDF:", ex); return false; } String resultFileName = ToolkitFileUtils.getTaskOutputPath(taskInfo, "concepts_solr.json"); try { FileOutputStream out = new FileOutputStream(resultFileName); JsonObjectBuilder job = Json.createObjectBuilder(); job.add("concepts_count", conceptHandler.getCountedPrefLabels()); results.put("concepts_count", Integer.toString(conceptHandler.getCountedPrefLabels())); job.add("concepts_text", conceptHandler.getConceptText()); results.put("concepts_solr", resultFileName); JsonWriter jsonWriter = Json.createWriter(out); jsonWriter.writeObject(job.build()); jsonWriter.close(); } catch (FileNotFoundException ex) { results.put(TaskStatus.EXCEPTION, "Exception in SolrIndexTransform while generating result"); logger.error("Exception in SolrIndexTransform generating result:", ex); return false; } return true; }
From source file:nl.sidn.dnslib.message.records.dnssec.NSEC3ParamResourceRecord.java
@Override public JsonObject toJSon() { JsonObjectBuilder builder = super.createJsonBuilder(); return builder.add("rdata", Json.createObjectBuilder().add("hash-algorithm", hashAlgorithm.name()).add("flags", flags) .add("optout", optout).add("iterations", (int) iterations).add("salt-length", saltLength) .add("salt", Hex.encodeHexString(salt))) .build();//from www . ja v a 2 s.c o m }
From source file:prod.products.java
private String getResults(String query, String... params) { Boolean Result = false; JsonArrayBuilder pList = Json.createArrayBuilder(); StringBuilder sb = new StringBuilder(); try (Connection cn = credentials.getConnection()) { PreparedStatement pstmt = cn.prepareStatement(query); for (int i = 1; i <= params.length; i++) { pstmt.setString(i, params[i - 1]); Result = true;/*from w w w . ja v a2s . c o m*/ } ResultSet rs = pstmt.executeQuery(); if (Result == false) { while (rs.next()) { JsonObjectBuilder productBuilder = Json.createObjectBuilder(); productBuilder.add("productId", rs.getInt("product_id")) .add("name", rs.getString("product_name")) .add("description", rs.getString("product_description")) .add("quantity", rs.getInt("quantity")); pList.add(productBuilder); } } else { while (rs.next()) { JsonObject jsonObt = Json.createObjectBuilder().add("productId", rs.getInt("product_id")) .add("name", rs.getString("product_name")) .add("description", rs.getString("product_description")) .add("quantity", rs.getInt("quantity")).build(); return jsonObt.toString(); } } } catch (SQLException ex) { Logger.getLogger(products.class.getName()).log(Level.SEVERE, null, ex); } return pList.build().toString(); }
From source file:example.SimpleChaincode.java
private String newErrorJson(final Throwable throwable, final String message, final Object... args) { final JsonObjectBuilder builder = Json.createObjectBuilder(); if (message != null) builder.add("Error", String.format(message, args)); if (throwable != null) { final StringWriter buffer = new StringWriter(); throwable.printStackTrace(new PrintWriter(buffer)); builder.add("Stacktrace", buffer.toString()); }//from w w w .j a v a2 s .co m return builder.build().toString(); }
From source file:nl.sidn.dnslib.message.records.dnssec.DNSKEYResourceRecord.java
@Override public JsonObject toJSon() { JsonObjectBuilder builder = super.createJsonBuilder(); return builder.add("rdata", Json.createObjectBuilder().add("flags", (int) flags)).add("protocol", protocol) .add("algorithm", algorithm.name()).add("zone-key", isZoneKey).add("sep-key", isSepKey) .add("keytag", keytag).build(); }
From source file:org.gameontext.mediator.models.Exits.java
@JsonIgnore public JsonObject toSimpleJsonList() { JsonObjectBuilder content = Json.createObjectBuilder(); if (n != null) { content.add("N", n.getDoor()); }/* w w w . j av a 2 s . com*/ if (s != null) { content.add("S", s.getDoor()); } if (e != null) { content.add("E", e.getDoor()); } if (w != null) { content.add("W", w.getDoor()); } if (u != null) { content.add("U", u.getDoor()); } if (d != null) { content.add("D", d.getDoor()); } return content.build(); }
From source file:co.runrightfast.core.application.event.AppEvent.java
/** * * @param json add event info to the supplied JsonObjectBuilder *///ww w . j a v a2 s . co m public void addEventInfo(@NonNull final JsonObjectBuilder json) { json.add("event", event).add("level", eventLevel.id).add("timestamp", getTimestamp()); addMessage(json); addException(json); addTags(json); addData(json); addVerticleId(json); }
From source file:org.grogshop.services.endpoints.impl.ShopUserProfileServiceImpl.java
@Override public Response get(@PathParam("id") Long user_id) throws ServiceException { Profile p = profileService.getById(user_id); if (p == null) { throw new ServiceException("Profile for " + user_id + " doesn't exists"); }/*from w ww . j a v a 2 s . c o m*/ JsonObjectBuilder jsonObjBuilder = Json.createObjectBuilder(); jsonObjBuilder.add("bio", (p.getIntroduction() == null) ? "" : p.getIntroduction()); jsonObjBuilder.add("location", (p.getPostcode() == null) ? "" : p.getPostcode()); jsonObjBuilder.add("username", (p.getRealname() == null) ? "" : p.getRealname()); JsonObject jsonObj = jsonObjBuilder.build(); return Response.ok(jsonObj.toString()).build(); }
From source file:com.product.ProductResource.java
/** * Retrieves representation of an instance of com.oracle.products.ProductResource * @return an instance of java.lang.String *///from w w w .ja va 2 s. c om @GET @Produces(MediaType.APPLICATION_JSON) public String getAllProducts() throws SQLException { if (conn == null) { return "not connected"; } else { String query = "Select * from product"; PreparedStatement pstmt = conn.prepareStatement(query); ResultSet rs = pstmt.executeQuery(); String result = ""; JSONArray productArr = new JSONArray(); while (rs.next()) { JsonObjectBuilder prodMap = Json.createObjectBuilder(); prodMap.add("productID", rs.getInt("product_id")); prodMap.add("name", rs.getString("name")); prodMap.add("description", rs.getString("description")); prodMap.add("quantity", rs.getInt("quantity")); productArr.add(prodMap); } result = productArr.toString(); return result.replace("},", "},\n"); } }
From source file:org.openlmis.converter.CreateObjectTypeConverter.java
@Override public void convert(JsonObjectBuilder builder, Mapping mapping, String value) { List<String> entries = Lists.newArrayList(StringUtils.split(value, ',')); JsonObjectBuilder inner = Json.createObjectBuilder(); for (String entry : entries) { List<String> keyValue = Lists.newArrayList(StringUtils.split(entry, ':')); if (keyValue.size() == 2) { inner.add(keyValue.get(0), keyValue.get(1)); } else {/*from w ww . java 2s . co m*/ logger.warn("Invalid map entry representation: {}. Desired format is \"<key>:<value>\".", entry); } } builder.add(mapping.getTo(), inner.build()); }