Java Code Examples for net.minidev.json.JSONArray#add()
The following examples show how to use
net.minidev.json.JSONArray#add() .
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: JwtTransformerTestCase.java From product-microgateway with Apache License 2.0 | 6 votes |
@BeforeClass public void start() throws Exception { String project = "jwtTransformerProject"; //Define application info Map<String, Object> claimMap = new HashMap<>(); ApplicationDTO application = new ApplicationDTO(); application.setName("jwtApp"); application.setTier("Unlimited"); application.setId((int) (Math.random() * 1000)); JSONArray scopes = new JSONArray(); scopes.add("admin"); scopes.add("write"); scopes.add("read"); claimMap.put("scp", scopes); jwtTokenProdWithScopes = TokenUtil.getJwtWithCustomClaimsTransformer(application, new JSONObject(), TestConstant.KEY_TYPE_PRODUCTION, 3600, claimMap); //generate apis with CLI and start the micro gateway server super.init(project, new String[]{"jwtTransformer/jwt_transformer.yaml", "mgw-JwtValueTransformer.jar"}, null, "confs/jwt-transformer-test-config.conf"); }
Example 2
Source File: StaticRoutingConverter.java From scheduler with GNU Lesser General Public License v3.0 | 6 votes |
/** * Convert a Routing implementation into a JSON object * * @param routing the routing implementation to convert * @return the JSON formatted routing object */ @Override public JSONObject toJSON(StaticRouting routing) { JSONObject o = new JSONObject(); o.put("type", getJSONId()); JSONArray a = new JSONArray(); Map<StaticRouting.NodesMap, Map<Link, Boolean>> routes = routing.getStaticRoutes(); for (Map.Entry<StaticRouting.NodesMap, Map<Link, Boolean>> e : routes.entrySet()) { StaticRouting.NodesMap nm = e.getKey(); JSONObject ao = new JSONObject(); ao.put("nodes_map", nodesMapToJSON(nm)); JSONArray links = new JSONArray(); Map<Link, Boolean> v = e.getValue(); for (Link l : v.keySet()) { JSONObject lo = new JSONObject(); lo.put("link", l.id()); lo.put("direction", routes.get(nm).get(l).toString()); links.add(lo); } ao.put("links", links); a.add(ao); } o.put(ROUTES_LABEL, a); return o; }
Example 3
Source File: RestControllerV2IT.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@Test @Order(8) void batchDelete() { JSONObject jsonObject = new JSONObject(); JSONArray entityIds = new JSONArray(); entityIds.add("55"); entityIds.add("57"); jsonObject.put("entityIds", entityIds); given(testUserToken) .contentType(APPLICATION_JSON) .body(jsonObject.toJSONString()) .when() .delete(API_V2 + "it_emx_datatypes_TypeTestv2") .then() .statusCode(NO_CONTENT); }
Example 4
Source File: WebServer.java From tracing-framework with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json"); response.setStatus(HttpServletResponse.SC_OK); String uri = request.getRequestURI(); int pathLen = request.getServletPath().length() + 1; String tagsString = uri.length() > pathLen ? uri.substring(pathLen) : ""; String[] tags = tagsString.split(","); JSONObject obj = new JSONObject(); for (String tag : tags) { JSONArray arr = new JSONArray(); Collection<TaskRecord> taskInfos = metadata.getTasksByTag(tag, 0, Integer.MAX_VALUE); for (TaskRecord t : taskInfos) { arr.add(t.getTaskId().toString()); } obj.put(tag, arr); } Writer out = response.getWriter(); out.write(obj.toJSONString()); }
Example 5
Source File: ConstraintsConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
/** * Serialise a list of sat-constraints. * @param e the list to serialise * @return the resulting encoded list * @throws JSONConverterException if the conversion failed */ public JSONArray toJSON(Collection<SatConstraint> e) throws JSONConverterException { JSONArray arr = new JSONArray(); for (SatConstraint cstr : e) { arr.add(toJSON(cstr)); } return arr; }
Example 6
Source File: RestControllerV2IT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test @Order(4) void batchCreateLocation() { JSONObject jsonObject = new JSONObject(); JSONArray entities = new JSONArray(); JSONObject entity = new JSONObject(); entity.put("Chromosome", "42"); entity.put("Position", 42); entities.add(entity); jsonObject.put("entities", entities); String expectedLocation = "/api/v2/it_emx_datatypes_Locationv2?q=Position=in=(\"42\")"; String expectedHref = "/api/v2/it_emx_datatypes_Locationv2/42"; given(testUserToken) .contentType(APPLICATION_JSON) .body(jsonObject.toJSONString()) .when() .post(API_V2 + "it_emx_datatypes_Locationv2") .then() .statusCode(RestTestUtils.CREATED) .body( "location", Matchers.equalTo(expectedLocation), "resources[0].href", Matchers.equalTo(expectedHref)); }
Example 7
Source File: RestControllerV2IT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test @Order(3) void batchCreate() { JSONObject jsonObject = new JSONObject(); JSONArray entities = new JSONArray(); JSONObject entity1 = new JSONObject(); entity1.put("value", "ref55"); entity1.put("label", "label55"); entities.add(entity1); JSONObject entity2 = new JSONObject(); entity2.put("value", "ref57"); entity2.put("label", "label57"); entities.add(entity2); jsonObject.put("entities", entities); given(testUserToken) .contentType(APPLICATION_JSON) .body(jsonObject.toJSONString()) .when() .post(API_V2 + "it_emx_datatypes_TypeTestRefv2") .then() .statusCode(RestTestUtils.CREATED) .body( "location", Matchers.equalTo( "/api/v2/it_emx_datatypes_TypeTestRefv2?q=value=in=(\"ref55\",\"ref57\")")); }
Example 8
Source File: ColType.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONArray toJSON(Object c) { JSONArray a = new JSONArray(); for (Object o : (Collection) c) { a.add(type.toJSON(o)); } return a; }
Example 9
Source File: EntityControllerIT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test @Order(1) void testCreateResource() { JSONArray jsonArray = new JSONArray(); jsonArray.add("str1"); jsonArray.add("str2"); JSONObject jsonObject = new JSONObject(); jsonObject.put("id", 25); jsonObject.put("label", "Row 25"); jsonObject.put("myBool", true); jsonObject.put("myDate", "2000-01-25"); jsonObject.put("myDateTime", "2000-01-24T21:02:03Z"); jsonObject.put("myDecimal", 25.1); jsonObject.put("myInt", 25); jsonObject.put("myLong", 3000000025L); jsonObject.put("myString", "String 25"); jsonObject.put("myText", "Text 25"); jsonObject.put("myXref", 5); jsonObject.put("myMref", jsonArray); given() .contentType(APPLICATION_JSON_VALUE) .body(jsonObject.toJSONString()) .post("/api/data/v3_MyDataset") .then() .statusCode(CREATED.value()) .header(LOCATION, RestAssured.baseURI + "/api/data/v3_MyDataset/25"); }
Example 10
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 11
Source File: AmongConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JSONObject toJSON(Among o) { JSONObject c = new JSONObject(); c.put("id", getJSONId()); c.put("vms", vmsToJSON(o.getInvolvedVMs())); JSONArray a = new JSONArray(); for (Collection<Node> grp : o.getGroupsOfNodes()) { a.add(nodesToJSON(grp)); } c.put("parts", a); c.put("continuous", o.isContinuous()); return c; }
Example 12
Source File: NetworkConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
/** * Convert a collection of switches to an array of JSON switches objects. * * @param c the collection of Switches * @return a json formatted array of Switches */ public JSONArray switchesToJSON(Collection<Switch> c) { JSONArray a = new JSONArray(); for (Switch s : c) { a.add(switchToJSON(s)); } return a; }
Example 13
Source File: JSONs.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
/** * Convert a collection nodes to an array of nodes identifiers. * * @param s the VMs * @return a json formatted array of integers */ public static JSONArray nodesToJSON(Collection<Node> s) { JSONArray a = new JSONArray(); for (Element e : s) { a.add(e.id()); } return a; }
Example 14
Source File: EleCheck.java From jelectrum with MIT License | 4 votes |
public static void checkServerVersion(EleConn conn) { JSONArray params = new JSONArray(); params.add("EleCheck"); JSONArray range = new JSONArray(); range.add("0.10"); range.add("1.4.2"); params.add(range); JSONObject msg = conn.request("server.version", params); JSONArray result = (JSONArray) msg.get("result"); String server_id = (String)result.get(0); String ver = (String)result.get(1); System.out.println("Server id: " + server_id); System.out.println("Server selected version: " + ver); }
Example 15
Source File: ConfigurationControllerTest.java From citrus-admin with Apache License 2.0 | 4 votes |
@Test public void testXmlDataDictionary() throws Exception { List<DataDictionaryType> dictionaries = controller.listDataDictionaries(); Assert.assertEquals(dictionaries.size(), 0L); JSONObject dictionary = new JSONObject(); JSONObject mappings = new JSONObject(); JSONArray mappingsArray = new JSONArray(); JSONObject mapping = new JSONObject(); mapping.put("path", "root"); mapping.put("value", "foo"); mappingsArray.add(mapping); mappings.put("mappings", mappingsArray); dictionary.put("id", "xmlDataDictionary"); dictionary.put("mappings", mappings); dictionary.put("mappingStrategy", DataDictionary.PathMappingStrategy.EXACT.toString()); controller.createDataDictionary("xml", dictionary); dictionaries = controller.listDataDictionaries(); Assert.assertEquals(dictionaries.size(), 1L); DataDictionaryType xmlDataDictionary = controller.getDataDictionary("xmlDataDictionary"); Assert.assertNotNull(xmlDataDictionary); Assert.assertEquals(xmlDataDictionary.getId(), "xmlDataDictionary"); Assert.assertEquals(xmlDataDictionary.getMappings().getMappings().size(), 1L); Assert.assertEquals(xmlDataDictionary.getMappings().getMappings().get(0).getPath(), "root"); Assert.assertEquals(xmlDataDictionary.getMappings().getMappings().get(0).getValue(), "foo"); Assert.assertEquals(xmlDataDictionary.getMappingStrategy(), DataDictionary.PathMappingStrategy.EXACT.toString()); dictionary.put("mappingStrategy", DataDictionary.PathMappingStrategy.STARTS_WITH.toString()); controller.updateDataDictionary(dictionary); xmlDataDictionary = controller.getDataDictionary("xmlDataDictionary"); Assert.assertNotNull(xmlDataDictionary); Assert.assertEquals(xmlDataDictionary.getMappingStrategy(), DataDictionary.PathMappingStrategy.STARTS_WITH.toString()); controller.deleteComponent("xmlDataDictionary"); dictionaries = controller.listDataDictionaries(); Assert.assertEquals(dictionaries.size(), 0L); Assert.assertNull(controller.getDataDictionary("xmlDataDictionary")); }
Example 16
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 17
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 wallet_data = (JSONObject) params.get("wallet"); WalletDatabase.Builder wallet_import = WalletDatabase.newBuilder(); JsonFormat.Parser parser = JsonFormat.parser(); parser.merge(wallet_data.toString(), wallet_import); WalletDatabase new_db = wallet_import.build(); List<AddressSpecHash> addresses = WalletUtil.testWallet( new_db ); if (client.getConfig().getBoolean("watch_only") && (new_db.getKeysCount() > 0)) { throw new ValidationException("Attempting to import wallet with keys into watch only wallet. Nope."); } client.getPurse().mergeIn( new_db ); JSONObject reply = new JSONObject(); JSONArray address_list = new JSONArray(); for(AddressSpecHash spec_hash : addresses) { String address = spec_hash.toAddressString( client.getParams() ); address_list.add(address); } reply.put("addresses", address_list); JSONArray keypair_list = new JSONArray(); for(WalletKeyPair pair : new_db.getKeysList()) { String key_string = HexUtil.getHexString( pair.getPublicKey() ); keypair_list.add(key_string); } reply.put("keys", keypair_list); return reply; }
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: EleCheck.java From jelectrum with MIT License | 3 votes |
public static void checkBlockHeaderCheckPoint(EleConn conn) throws Exception { //int blk_n = 109; //int cp = 32911; Random rnd = new Random(); for(int i=0; i<20; i++) { JSONArray params = new JSONArray(); int cp = rnd.nextInt(630000)+10; int blk_n = rnd.nextInt(cp); //cp = 5; //blk_n = 2; params.add(blk_n); params.add(cp); JSONObject msg = conn.request("blockchain.block.header", params); JSONObject result = (JSONObject) msg.get("result"); String header = (String) result.get("header"); if (header.length() != 160) throw new Exception("Header not 160 chars"); JSONArray branch = (JSONArray) result.get("branch"); String header_hex = (String) result.get("header"); String root = (String) result.get("root"); validateMerkle(HexUtil.hexStringToBytes(header_hex), branch, blk_n, cp, root); } }
Example 20
Source File: EleCheck.java From jelectrum with MIT License | 3 votes |
public static void checkBlockHeaders(EleConn conn) throws Exception { Random rnd = new Random(); for(int i=0; i<20; i++) { JSONArray params = new JSONArray(); int cp = rnd.nextInt(600000)+1000; int count = rnd.nextInt(Math.min(4000, cp-1))+1; int height = rnd.nextInt(cp-count); params.add(height); params.add(count); params.add(cp); JSONObject msg = conn.request("blockchain.block.headers", params); JSONObject result = (JSONObject) msg.get("result"); String hex = (String) result.get("hex"); JSONArray branch = (JSONArray) result.get("branch"); String root = (String) result.get("root"); String last_block_hex = hex.substring( hex.length() - 160); Assert.assertEquals(0 , hex.length() % 160); int blk_n = height + hex.length()/160 - 1; validateMerkle(HexUtil.hexStringToBytes(last_block_hex), branch, blk_n, cp, root); } }