SchemaUtils { public static JSONObject createJSONObject(Map<String, String> map) { JSONObject jo = new JSONObject(); for (Map.Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); try { jo.put(key, value); } catch (JSONException ex) { throw new RuntimeException(ex); } } return jo; } private  SchemaUtils(); static String jarResourceFileToString(String resource); static String inputStreamToString(InputStream inputStream); static boolean checkValidKeys(JSONObject jo, Fields fields); static void checkValidKeysEx(JSONObject jo, Fields fields); static boolean checkValidKeys(JSONObject jo, Collection<Fields> fieldsCollection); static boolean checkValidKeys(JSONObject jo, List<Fields> fieldsCollection); static boolean checkValidKeysEx(JSONObject jo, Collection<Fields> fieldsCollection); static boolean checkValidKeysExHelper(JSONObject jo, Collection<Fields> fieldsCollection); static boolean checkValidKeysEx(JSONObject jo, List<Fields> fieldsCollection); static Set<String> getSetOfJSONKeys(JSONObject jo); static Map<String, String> convertFieldToType(Map<String, Type> fieldToType); static JSONArray findFirstKeyJSONArray(JSONObject jo, String key); static JSONArray findFirstKeyJSONArray(JSONArray ja, String key); static JSONObject findFirstKeyJSONObject(JSONObject jo, String key); static JSONObject findFirstKeyJSONObject(JSONArray ja, String key); static Map<String, String> extractMap(JSONObject jo); static JSONObject createJSONObject(Map<String, String> map); static List<String> getStringsFromJSONArray(JSONArray jsonStringArray); static List<String> getTags(JSONObject jo); static final String FIELD_TAGS; }
@Test public void createJSONObjectFromMapTest() throws Exception { Map<String, String> mapVals = Maps.newHashMap(); mapVals.put("a", "1"); mapVals.put("b", "2"); JSONObject jo = SchemaUtils.createJSONObject(mapVals); Assert.assertEquals(2, jo.length()); Assert.assertEquals("1", jo.get("a")); Assert.assertEquals("2", jo.get("b")); }