/** * Test getting all configuration properties from EzConfigurationService. * * @throws java.lang.Exception If something bad happens */ @Test public void testGetAllProperties() throws Exception { JsonParser parser = new JsonParser(); JsonObject obj = parser .parse( "{\"application.name\":\"testapp\",\"web.application.metrics.endpoint\":\"https://test.com/stats\",\"web.application.external.domain\":\"foo.com\",\"web.application.metrics.siteid\":\"foobar\"}") .getAsJsonObject(); if (obj.isJsonNull()) { logger.info(LINE_SEPARATOR + "The Json object is NULL" + LINE_SEPARATOR); } else { logger.info(LINE_SEPARATOR + "The Json object is not null" + LINE_SEPARATOR); } Gson gson = new Gson(); // With a HTTP GET request to : // http://<<HOST>>/ezconfiguration-webservice/ezconfiguration // We expect this string to be returned String expString = gson.toJson(obj); testEzConfigWS(expString); }
// Transform the json-type feature to mat-type public static Mat json2mat(String json) { JsonParser parser = new JsonParser(); JsonElement parseTree = parser.parse(json); // Verify the input is JSON type if (!parseTree.isJsonObject()) { System.out.println("The input is not a JSON type...\nExiting..."); System.exit(1); } JsonObject jobj = parser.parse(json).getAsJsonObject(); if (jobj == null || !jobj.isJsonObject() || jobj.isJsonNull()) { return null; } // Detect broken/null features JsonElement r = jobj.get("rows"); if (r == null) { return null; } int rows = jobj.get("rows").getAsInt(); int cols = jobj.get("cols").getAsInt(); int type = jobj.get("type").getAsInt(); String data = jobj.get("data").getAsString(); String[] pixs = data.split(","); Mat descriptor = new Mat(rows, cols, type); for (String pix : pixs) { String[] tmp = pix.split(" "); int r_pos = Integer.valueOf(tmp[0]); int c_pos = Integer.valueOf(tmp[1]); double rgb = Double.valueOf(tmp[2]); descriptor.put(r_pos, c_pos, rgb); } return descriptor; }