SchemaUtils { public static List<String> getTags(JSONObject jo) throws JSONException { if (jo.has(FIELD_TAGS)) { return getStringsFromJSONArray(jo.getJSONArray(FIELD_TAGS)); } else { return Collections.emptyList(); } } 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 extractTagsTest() throws Exception { List<String> expected = Lists.newArrayList("a", "b", "c"); JSONObject jo = new JSONObject(); JSONArray ja = new JSONArray(); ja.put("a").put("b").put("c"); jo.put(SchemaUtils.FIELD_TAGS, ja); Assert.assertEquals(expected, SchemaUtils.getTags(jo)); }