List of usage examples for javax.json JsonObjectBuilder build
JsonObject build();
From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java
private JsonObject idToJsonObject() { JsonObjectBuilder ob = Json.createObjectBuilder(); ob.add("id", enrollmentID); ob.add("type", type); if (null != maxEnrollments) { ob.add("max_enrollments", maxEnrollments); }/* w w w .jav a2s .c o m*/ if (affiliation != null) { ob.add("affiliation", affiliation); } JsonArrayBuilder ab = Json.createArrayBuilder(); for (Attribute attr : attrs) { ab.add(attr.toJsonObject()); } ob.add("attrs", ab.build()); if (this.secret != null) { ob.add("secret", secret); } if (client.getCAName() != null) { ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName()); } return ob.build(); }
From source file:com.amazon.alexa.avs.config.DeviceConfig.java
/** * Serialize this object to JSON./*from ww w. ja v a2 s. co m*/ * * @return A JSON representation of this object. */ public JsonObject toJson() { JsonObjectBuilder builder = Json.createObjectBuilder().add(PRODUCT_ID, productId).add(DSN, dsn) .add(PROVISIONING_METHOD, provisioningMethod.toString()) .add(WAKE_WORD_AGENT_ENABLED, wakeWordAgentEnabled).add(LOCALE, locale.toLanguageTag()) .add(AVS_HOST, avsHost.toString()); if (companionAppInfo != null) { builder.add(COMPANION_APP, companionAppInfo.toJson()); } if (companionServiceInfo != null) { builder.add(COMPANION_SERVICE, companionServiceInfo.toJson()); } return builder.build(); }
From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.UpdateRegisteredSEEsHandler.java
private Report updateSEE(SEE see) throws ClientProtocolException, IOException { String serviceName = "updateSEE"; JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); if (see.getSeeID() != null && !see.getSeeID().trim().isEmpty()) { jsonBuilder.add("seeId", see.getSeeID()); }/*from w ww . j av a 2 s . c o m*/ if (see.getMESNodeID() != null && !see.getMESNodeID().trim().isEmpty()) { jsonBuilder.add("nodeId", see.getMESNodeID().replaceAll("ns", "").replaceAll("i", "").replace("=", "")); } if (see.getResource() != null) { jsonBuilder.add("assetTypeNames", see.getResource().getName()); } if (see.getOpcUAAddress() != null && !see.getOpcUAAddress().trim().isEmpty()) { jsonBuilder.add("opcuaAddress", see.getOpcUAAddress()); } jsonBuilder.add("simulation", see.isSimulation() + ""); if (see.getAmlDescription() != null && !see.getAmlDescription().trim().isEmpty()) { jsonBuilder.add("amlFile", see.getAmlDescription()); } HttpPost request = new HttpPost(AMSServiceUtility.serviceAddress + serviceName); request.setEntity(new StringEntity(jsonBuilder.build().toString(), "UTF-8")); System.out.println(request.getRequestLine() + " ====================================="); request.setHeader("Content-type", "application/json"); HttpClient client = HttpClientBuilder.create().build(); ; HttpResponse response = client.execute(request); String resp = EntityUtils.toString(response.getEntity()); return JSONUtility.convertToObject(resp, Report.class); }
From source file:skillpro.asset.views.wizardpages.SEEResultPage.java
private void registerSEE(SEE see) throws ClientProtocolException, IOException { JsonObjectBuilder jsonBuilder = Json.createObjectBuilder(); if (see.getSeeID() != null && !see.getSeeID().trim().isEmpty()) { jsonBuilder.add("seeId", see.getSeeID() == null ? UUID.randomUUID().toString() : see.getSeeID()); }// w w w .j av a 2 s .co m if (see.getMESCommunication().getFirstElement() == MESCommType.OPCUA) { jsonBuilder.add("opcuaAddress", see.getMESCommunication().getSecondElement()); } if (see.getResource() != null) { jsonBuilder.add("assetTypeNames", see.getResource().getName()); } jsonBuilder.add("simulation", see.isSimulation() + ""); String amlDescription = see.getAmlDescription(); if (amlDescription != null && !amlDescription.trim().isEmpty()) { jsonBuilder.add("amlFile", amlDescription); } HttpPost request = new HttpPost(AMSServiceUtility.serviceAddress + "registerSEE"); request.setEntity(new StringEntity(jsonBuilder.build().toString(), "UTF-8")); request.setHeader("Content-type", "application/json"); HttpClient client = HttpClientBuilder.create().build(); ; client.execute(request); }
From source file:com.buffalokiwi.aerodrome.jet.products.JetAPIProduct.java
/** * Adds product quantity and inventory data * @param product product data//from w w w .ja v a 2 s. c om * @return success * @throws APIException * @throws JetException */ @Override public IJetAPIResponse sendPutProductInventory(final String sku, final List<FNodeInventoryRec> nodes) throws JetException, APIException { Utils.checkNull(sku, "sku"); Utils.checkNull(nodes, "nodes"); APILog.info(LOG, "Sending", sku, "inventory"); final JsonObjectBuilder o = Json.createObjectBuilder(); if (!nodes.isEmpty()) { final JsonArrayBuilder a = Json.createArrayBuilder(); nodes.forEach(v -> a.add(v.toJSON())); o.add("fulfillment_nodes", a.build()); } final IJetAPIResponse response = patch(config.getAddProductInventoryUrl(sku), o.build().toString(), getJSONHeaderBuilder().build()); return response; }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public String jsonError(String id, int code, String message) { JsonObjectBuilder builder = Json.createObjectBuilder().add(JSONRPC_REALM, JSONRPC_VERSION) .addNull(JSONRPC_RESULT);//from w ww. j a v a 2 s. co m JsonObject error = Json.createObjectBuilder().add(JSONRPC_CODE, code).add(JSONRPC_MESSAGE, message) .addNull(JSONRPC_DATA).build(); builder.add(JSONRPC_ERROR, error).add(JSONRPC_ID, id); return String.valueOf(builder.build()); }
From source file:be.fedict.dcat.datagovbe.Drupal.java
/** * Add a dataset to the Drupal website.//from ww w . j a va 2 s.c o m * * @param uri identifier of the dataset * @throws RepositoryException */ private void add(IRI uri) throws RepositoryException { Map<IRI, ListMultimap<String, String>> dataset = store.queryProperties(uri); if (dataset.isEmpty()) { logger.warn("Empty dataset for {}", uri.stringValue()); return; } for (String lang : langs) { if (!hasLang(dataset, lang)) { continue; } JsonObjectBuilder builder = Json.createObjectBuilder(); addDataset(builder, dataset, lang); // Get DCAT distributions List<String> dists = getMany(dataset, DCAT.DISTRIBUTION, ""); addDists(builder, dists, lang); // Add new or update existing dataset ? String id = getOne(dataset, DCTERMS.IDENTIFIER, ""); String node = checkExistsTrans(builder, id, lang); // Build the JSON array JsonObject obj = builder.build(); logger.debug(obj.toString()); Request r = node.isEmpty() ? prepare(Drupal.POST, Drupal.NODE) : prepare(Drupal.PUT, Drupal.NODE + "/" + node); r.bodyString(obj.toString(), ContentType.APPLICATION_JSON); try { StatusLine status = exec.authPreemptive(host).execute(r).returnResponse().getStatusLine(); logger.debug(status.toString()); } catch (IOException ex) { logger.error("Could not update {}", uri.toString(), ex); } } }
From source file:com.open.shift.support.controller.SupportResource.java
@GET @Produces(MediaType.APPLICATION_JSON)// w w w. j a v a 2 s. c om @Path("piechart") public JsonObject generatePieChart() throws Exception { URL u = ctx.getResource("/WEB-INF/classes/templates/pie.json"); String pieJson = null; if (OS.indexOf("win") >= 0) { pieJson = u.toString().substring(6); } else if (OS.indexOf("nux") >= 0) { pieJson = u.toString().substring(5); } JsonReader reader = Json.createReader(new FileReader(pieJson)); JsonObject main = reader.readObject(); JsonObjectBuilder title = Json.createObjectBuilder().add("text", "Companies Contribution in Deposits"); JsonArrayBuilder data = Json.createArrayBuilder().add(Json.createArrayBuilder().add("Infosys").add(45.0)) .add(Json.createArrayBuilder().add("TCS").add(26.8)) .add(Json.createArrayBuilder().add("Oracle").add(8.5)) .add(Json.createArrayBuilder().add("Accenture").add(6.2)).add(Json.createObjectBuilder() .add("name", "IBM").add("y", 12.8).add("sliced", true).add("selected", true)); JsonArrayBuilder series = Json.createArrayBuilder().add( Json.createObjectBuilder().add("type", "pie").add("name", "Deposit Contributed").add("data", data)); JsonObjectBuilder mainJsonObj = Json.createObjectBuilder(); for (Map.Entry<String, JsonValue> entrySet : main.entrySet()) { String key = entrySet.getKey(); JsonValue value = entrySet.getValue(); mainJsonObj.add(key, value); } mainJsonObj.add("title", title.build()).add("series", series.build()); return mainJsonObj.build(); }
From source file:org.btc4j.daemon.BtcJsonRpcHttpClient.java
public JsonValue invoke(String method, JsonArray parameters) throws BtcException { JsonObjectBuilder builder = Json.createObjectBuilder(); builder.add(JSONRPC_REALM, JSONRPC_VERSION).add(JSONRPC_METHOD, method); if (parameters != null) { builder.add(JSONRPC_PARAMS, parameters); } else {/*from ww w . j a va 2s . c o m*/ builder.addNull(JSONRPC_PARAMS); } String guid = UUID.randomUUID().toString(); builder.add(JSONRPC_ID, guid); JsonObject request = builder.build(); JsonObject response = jsonObject(jsonValue(jsonInvoke(String.valueOf(request)))); if (response == null) { LOG.severe(BTC4J_DAEMON_DATA_NULL_JSON); throw new BtcException(BtcException.BTC4J_ERROR_CODE, BtcException.BTC4J_ERROR_MESSAGE + ": " + BTC4J_DAEMON_DATA_NULL_JSON); } if (!(guid.equals(jsonId(response)))) { LOG.severe(BTC4J_DAEMON_DATA_INVALID_ID); throw new BtcException(BtcException.BTC4J_ERROR_CODE, BtcException.BTC4J_ERROR_MESSAGE + ": " + BTC4J_DAEMON_DATA_INVALID_ID); } JsonValue error = response.get(JSONRPC_ERROR); if ((error != null) && (error.getValueType().equals(ValueType.OBJECT))) { JsonObject errorObj = (JsonObject) error; int code = errorObj.getInt(JSONRPC_CODE); String message = errorObj.getString(JSONRPC_MESSAGE); JsonObject data = (JsonObject) errorObj.get(JSONRPC_DATA); String dataStr = (data == null) ? "" : (" " + String.valueOf(data)); LOG.severe("error: " + code + " " + message + dataStr); throw new BtcException(code, message + dataStr); } return response.get(JSONRPC_RESULT); }
From source file:ch.bfh.abcvote.util.controllers.CommunicationController.java
/** * Posts the given ballot to the bulletin board * @param ballot Ballot to be posted to the bulletin board * @param useTor Boolean indicating if Ballot should be posted over the Tor network *//*from ww w. j a v a 2s . c o m*/ public void postBallot(Ballot ballot, Boolean useTor) { JsonObjectBuilder jBuilder = Json.createObjectBuilder(); //Translate ballot object into a json string JsonArrayBuilder optionsBuilder = Json.createArrayBuilder(); for (String option : ballot.getSelectedOptions()) { optionsBuilder.add(option); } jBuilder.add("e", optionsBuilder); jBuilder.add("u_Hat", ballot.getU_HatString()); jBuilder.add("c", ballot.getCString()); jBuilder.add("d", ballot.getDString()); jBuilder.add("pi1", ballot.getPi1String()); jBuilder.add("pi2", ballot.getPi2String()); jBuilder.add("pi3", ballot.getPi3String()); JsonObject model = jBuilder.build(); //josn gets posted to the bulletin board try { boolean requestOK = postJsonStringToURL( bulletinBoardUrl + "/elections/" + ballot.getElection().getId() + "/ballots", model.toString(), useTor); if (requestOK) { System.out.println("Ballot posted!"); } else { System.out.println("Was not able to post Ballot!"); } } catch (IOException ex) { System.out.println("Was not able to post Ballot!"); } }