@Override public void read(JSONObject object) throws JSONException { super.read(object); setProperties(JSONUtils.readMap(object, PROPERTIES)); }
@Test public void writeReadMap() throws JSONException { /* Create a test map. */ final Map<String, String> map = new HashMap<>(); map.put("key", "value"); /* Write to JSON object. */ JSONStringer writer = new JSONStringer(); writer.object(); JSONUtils.writeMap(writer, "map", map); writer.endObject(); /* Convert to string. */ String json = writer.toString(); assertNotNull(json); /* Read a JSON object and verify. */ JSONObject object = new JSONObject(json); assertEquals(map, JSONUtils.readMap(object, "map")); }
@Test public void readKeyNotExists() throws JSONException { /* Create an empty JSON object. */ JSONObject object = new JSONObject("{}"); /* Verify. */ assertNull(JSONUtils.readInteger(object, "key")); assertNull(JSONUtils.readLong(object, "key")); assertNull(JSONUtils.readBoolean(object, "key")); assertNull(JSONUtils.readMap(object, "key")); assertNull(JSONUtils.readArray(object, "key", new MockLogFactory())); }