Java Code Examples for net.minidev.json.JSONObject#put()
The following examples show how to use
net.minidev.json.JSONObject#put() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeptRepositoryTest.java From spring-data-jpa-demo with Apache License 2.0 | 6 votes |
/** * Update by id. * * @throws Exception the exception * @see DeptRepository#save(Object) */ @Test void updateById() throws Exception { JSONObject param = new JSONObject(); param.put("name", "This is renamed dept."); this.mockMvc.perform( patch(basePath + "/" + RESOURCE_NAME + "/{id}", id) .contentType(MediaTypes.HAL_JSON) .content(param.toJSONString())) .andExpect(status().isOk()) .andDo(document(RESOURCE_NAME + "-update", selfLinksSnippet, pathParameters( parameterWithName("id").description("部门编号") ), requestFields( fieldWithPath("name").description("新的部门名称") ), responseFields )); }
Example 2
Source File: BlockApi.java From nem-apps-lib with MIT License | 5 votes |
/** * Gets the block by height and blocktype. * * @param height the height * @param blockType the block type * @return the block by height * @throws InterruptedException the interrupted exception * @throws ExecutionException the execution exception */ public static Block getBlockByHeight(int height, int blockType) throws InterruptedException, ExecutionException { Deserializer des; JSONObject jsonHeight = new JSONObject(); jsonHeight.put("height", height); des = NemAppsLibGlobals.CONNECTOR.postAsync(NemAppsLibGlobals.getNodeEndpoint(), NisApiId.NIS_REST_BLOCK_AT_PUBLIC, new HttpJsonPostRequest(jsonHeight)).exceptionally(fn -> { fn.printStackTrace(); return null; }).get(); return new Block(blockType, DeserializationOptions.NON_VERIFIABLE, des); }
Example 3
Source File: SplitConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONObject toJSON(Split o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); JSONArray a = new JSONArray(); for (Collection<VM> grp : o.getSets()) { a.add(vmsToJSON(grp)); } c.put("parts", a); c.put("continuous", o.isContinuous()); return c; }
Example 4
Source File: ITPutRethinkDBTest.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testValidSingleMessageTwiceConflictUpdate() { runner.assertValid(); RethinkDB.r.db(dbName).table(table).delete().run(connection); long count = RethinkDB.r.db(dbName).table(table).count().run(connection); assertEquals("Count should be same", 0L, count); JSONObject message = new JSONObject(); message.put("id", "rethinkdb"); byte [] bytes = message.toJSONString().getBytes(); runner.enqueue(bytes); runner.run(1,false,true); List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1"); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); runner.enqueue(bytes); runner.run(1,true,true); flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); assertNotNull(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"0"); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"1"); assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); count = RethinkDB.r.db(dbName).table(table).count().run(connection); assertEquals("Count should be same", 1L, count); }
Example 5
Source File: ConstraintConverterTest.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testCheckId() throws JSONConverterException { ConstraintConverter<?> c = new Mock<>("foo"); JSONObject o = new JSONObject(); o.put("id", "foo"); c.checkId(o); }
Example 6
Source File: GetTagDataStatisticsService.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
/** * * @param crisisCode * @param attributeCode * @param granularity * @param startTime * @return Count per label in the specified time window at the given granularity, for crisisCode and attributeCode */ public JSONObject getTagCountInTimeWindow(String crisisCode, String attributeCode, Long granularity, Long startTime) { //long timeGranularity = DateFormatConfig.parseTime(granularity); // First get the list of data points from DB List<TagData> tagDataList = tagDataEJB.getDataByGranularityInTimeWindow(crisisCode, attributeCode, null, startTime, granularity); // Now the real work - count and send response TimeWindowTagCountDTO dto = new TimeWindowTagCountDTO(); JSONObject json = new JsonResponse().getNewJsonResponseObject(crisisCode, attributeCode, granularity, startTime, null); if (tagDataList != null) { try { List<TagCountDTO> dtoList = new ArrayList<TagCountDTO>(); for (TagData t: tagDataList) { dtoList.add(TagCountDTOHelper.convertTagDataToDTO(t)); logger.info("tag: " + t.getLabelCode() + ", count: " + t.getCount()); } dto = TimeWindowTagCountDTOHelper.convertTagCountDTOListToDTO(startTime, dtoList); json.put("data", dto); } catch (Exception e) { json = JsonResponse.addError(json); logger.error("Error in serializing fetched tag count data", e); } } return json; }
Example 7
Source File: RpcServerHandler.java From snowblossom with Apache License 2.0 | 5 votes |
@Override protected JSONObject processRequest(JSONRPC2Request req, MessageContext ctx) throws Exception { ChainHash tx_hash = new ChainHash(HexUtil.hexStringToBytes(RpcUtil.requireString(req, "tx_hash"))); Map<String, Object> params = req.getNamedParams(); JSONObject reply = new JSONObject(); Transaction tx = client.getStub().getTransaction(RequestTransaction.newBuilder().setTxHash(tx_hash.getBytes()).build()); if (tx == null) { throw new Exception("Unknown transaction: " + tx_hash); } boolean as_json = false; if (params.containsKey("send_json")) { as_json = (boolean) params.get("send_json"); } TransactionInner inner = TransactionUtil.getInner(tx); reply.put("tx_hash", HexUtil.getHexString(tx.getTxHash())); reply.put("tx_data", HexUtil.getHexString(tx.toByteString())); reply.put("fee", inner.getFee()); TransactionStatus status = client.getStub().getTransactionStatus(RequestTransaction.newBuilder().setTxHash(tx_hash.getBytes()).build()); reply.put("status", RpcUtil.protoToJson(status)); if (as_json) { reply.put("tx_json", RpcUtil.protoToJson(tx)); reply.put("tx_inner_json", RpcUtil.protoToJson(inner)); } return reply; }
Example 8
Source File: LonelyConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONObject toJSON(Lonely o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("vms", vmsToJSON(o.getInvolvedVMs())); c.put("continuous", o.isContinuous()); return c; }
Example 9
Source File: YDPasswordLoginRequest.java From mclauncher-api with MIT License | 5 votes |
@Override public JSONObject toJSON() { JSONObject obj = new JSONObject(); obj.put("agent", agentObj); obj.put("clientToken", token); obj.put("username", user); obj.put("password", pass); return obj; }
Example 10
Source File: TestInvalidNumber.java From json-smart-v2 with Apache License 2.0 | 5 votes |
public void testF2() { String test = "51e+88"; JSONObject o = new JSONObject(); o.put("a", test); String comp = JSONValue.toJSONString(o, JSONStyle.MAX_COMPRESS); assertEquals("{a:\"51e+88\"}", comp); o = JSONValue.parse(comp, JSONObject.class); assertEquals(o.get("a"), test); }
Example 11
Source File: BlockApi.java From nem-apps-lib with MIT License | 5 votes |
/** * Gets the block by height. * * @param height the height * @return the block by height * @throws InterruptedException the interrupted exception * @throws ExecutionException the execution exception */ public static Block getBlockByHeight(int height) throws InterruptedException, ExecutionException { Deserializer des; JSONObject jsonHeight = new JSONObject(); jsonHeight.put("height", height); des = NemAppsLibGlobals.CONNECTOR.postAsync(NemAppsLibGlobals.getNodeEndpoint(), NisApiId.NIS_REST_BLOCK_AT_PUBLIC, new HttpJsonPostRequest(jsonHeight)).exceptionally(fn -> { fn.printStackTrace(); return null; }).get(); return new Block(BlockTypes.REGULAR, DeserializationOptions.NON_VERIFIABLE, des); }
Example 12
Source File: ScheduleConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONObject toJSON(Schedule o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); if (o.getNode() != null) { c.put("node", JSONs.elementToJSON(o.getNode())); } else { c.put("vm", JSONs.elementToJSON(o.getVM())); } c.put("start",o.getStart()); c.put("END", o.getEnd()); return c; }
Example 13
Source File: GetTagDataStatisticsService.java From AIDR with GNU Affero General Public License v3.0 | 5 votes |
public JSONObject getTagCountSumByGranularity(String crisisCode, Long startTime) { List<Long> gList = tagDataEJB.getGranularitiesForCrisis(crisisCode); Map<String, Long> countList = tagDataEJB.getTagCountByCrisisGranularity(crisisCode, startTime); JSONObject json = new JSONObject(); json.put("crisisCode", crisisCode); json.put("startTime", startTime); if (gList != null) { json.put("granularities", gList); json.put("data", countList); } return json; }
Example 14
Source File: IndexController.java From springboot-shiro-cas-mybatis with MIT License | 4 votes |
@RequestMapping(value = "/logout", method = { RequestMethod.POST, RequestMethod.GET }) public Object logout(){ JSONObject result = new JSONObject(); result.put("logoutUrl", logoutUrl+"?service=" +serviceUrl); return result; }
Example 15
Source File: ShutdownNodeConverter.java From scheduler with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void fillJSON(final ShutdownNode action, final JSONObject ob) { ob.put(NODE_LABEL, JSONs.elementToJSON(action.getNode())); }
Example 16
Source File: Persister4TaggerAPI.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
/** * * @param collectionCode * @return CSV format output(tweetIds only) from JSON filtered by user provided list of label names * @throws UnknownHostException */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/filter/genTweetIdsOnly") public Response generateTweetsIDSOnlyCSVFromAllJSONFiltered(String queryString, @QueryParam("collectionCode") String collectionCode, @QueryParam("exportLimit") Integer exportLimit, @QueryParam("removeRetweet") boolean removeRetweet, @QueryParam("userName") String userName) throws UnknownHostException { DeserializeFilters des = new DeserializeFilters(); JsonQueryList queryList = des.deserializeConstraints(queryString); JsonDeserializer jsonD = new JsonDeserializer(); logger.info("received request for collection: " + collectionCode); if (queryList != null) { logger.info(collectionCode + ": received constraints = " + queryList.toString()); } else { logger.info(collectionCode + ": received constraints = " + queryList); } if (null == exportLimit) exportLimit = Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)); Map<String, Object> result = jsonD.generateClassifiedJson2TweetIdsOnlyCSVFiltered(collectionCode, exportLimit, queryList, userName, removeRetweet); logger.info("Done processing request for collection: " + collectionCode + ", returning created file: " + result.get("fileName")); JSONObject obj = new JSONObject(); obj.put("feedCount", result.get("count")); if ((Integer) result.get("count") < Integer.parseInt(PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT))) { obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true)); logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true)); return Response.ok(obj.toJSONString()) .allow("POST", "OPTIONS", "HEAD") .header("Access-Control-Allow-Origin", "*") .header("Access-Control-Allow-Credentials", "true") .header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD") .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With") .build(); } else { obj.putAll(ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true)); logger.info("Returning JSON object: " + ResultStatus.getUIWrapper(collectionCode, PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_PREFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.DEFAULT_TWEETID_VOLUME_LIMIT)+ PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.TWEET_DOWNLOAD_LIMIT_MSG_SUFFIX) + PersisterConfigurator.getInstance().getProperty(PersisterConfigurationProperty.PERSISTER_CHANGE_NOTIFY_MSG), result.get("fileName").toString(), true)); return Response.ok(obj.toJSONString()) .allow("POST", "OPTIONS", "HEAD") .header("Access-Control-Allow-Origin", "*") .header("Access-Control-Allow-Credentials", "true") .header("Access-Control-Allow-Methods", "POST, OPTIONS, HEAD") .header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With") .build(); } }
Example 17
Source File: MinMTTRMigConverter.java From scheduler with GNU Lesser General Public License v3.0 | 4 votes |
@Override public JSONObject toJSON(MinMTTRMig o) { JSONObject c = new JSONObject(); c.put("id", o.id()); return c; }
Example 18
Source File: RpcServerHandler.java From snowblossom with Apache License 2.0 | 4 votes |
@Override protected JSONObject processRequest(JSONRPC2Request req, MessageContext ctx) throws Exception { Map<String, Object> params = req.getNamedParams(); JSONObject reply = new JSONObject(); List<TransactionBridge> bridges = null; if ((params != null) && (params.containsKey("address"))) { String address = (String)params.get("address"); AddressSpecHash hash = new AddressSpecHash(address, client.getParams()); bridges = client.getSpendable(hash); } else { bridges = client.getAllSpendable(); } JSONArray unspent = new JSONArray(); for(TransactionBridge br : bridges) { if (!br.spent) { JSONObject utxo = new JSONObject(); UTXOEntry e = br.toUTXOEntry(); AddressSpecHash spec_hash = new AddressSpecHash(e.getSpecHash()); utxo.put("address", spec_hash.toAddressString(client.getParams())); utxo.put("src_tx", HexUtil.getHexString(e.getSrcTx())); utxo.put("src_tx_out_idx", e.getSrcTxOutIdx()); utxo.put("value", e.getValue()); utxo.put("confirmed", !br.unconfirmed); unspent.add(utxo); } } reply.put("unspent", unspent); return reply; }
Example 19
Source File: SecretDetectorTest.java From snowflake-jdbc with Apache License 2.0 | 4 votes |
@Test public void testMaskJsonArray() { final String connStr = "https://snowflake.fakehostname.local:fakeport?LOGINTIMEOUT=20&ACCOUNT=fakeaccount&PASSWORD=fakepassword&USER=fakeuser"; final String maskedConnStr = "https://snowflake.fakehostname.local:fakeport?LOGINTIMEOUT=20&ACCOUNT=fakeaccount&PASSWORD=****"; final String pwdStr = "password=ThisShouldBeMasked"; final String maskedPwdStr = "password=****"; JSONObject obj = generateJsonObject(); obj.put("connStr", connStr); JSONObject maskedObj = generateJsonObject(); maskedObj.put("connStr", maskedConnStr); JSONArray array = new JSONArray(); array.add(obj); array.add(pwdStr); JSONArray maskedArray = new JSONArray(); maskedArray.add(maskedObj); maskedArray.add(maskedPwdStr); assertThat("jsonArray is not masked successfully", maskedArray.equals(SecretDetector.maskJsonArray(array))); JSONObject obj1 = generateJsonObject(); obj1.put("connStr", connStr); JSONObject maskedObj1 = generateJsonObject(); maskedObj1.put("connStr", maskedConnStr); JSONArray array1 = new JSONArray(); array1.add(obj1); array1.add(pwdStr); JSONArray maskedArray1 = new JSONArray(); maskedArray1.add(maskedObj1); maskedArray1.add(maskedPwdStr); JSONObject nestedObjArray = generateJsonObject(); nestedObjArray.put("array", array1); JSONObject maskedNestedObjArray = generateJsonObject(); maskedNestedObjArray.put("array", maskedArray1); assertThat("JSONArray within JSONObject is not masked successfully", maskedNestedObjArray.equals(SecretDetector.maskJsonObject(nestedObjArray))); }
Example 20
Source File: MinMTTRConverter.java From scheduler with GNU Lesser General Public License v3.0 | 4 votes |
@Override public JSONObject toJSON(MinMTTR o) { JSONObject c = new JSONObject(); c.put("id", o.id()); return c; }