@SuppressWarnings("unchecked") private static Map<String, Object> parse(String jsonString) { return (Map<String, Object>)JSON.parse(jsonString); }
@Test @SuppressWarnings("unchecked") public void testWriteJson() throws Exception { StringWriter sw = new StringWriter(); ConfServlet.writeResponse(getTestConf(), sw, "json"); String json = sw.toString(); boolean foundSetting = false; Set<String> programSet = new HashSet<>(); programSet.add("programatically"); programSet.add("programmatically"); Object parsed = JSON.parse(json); Object[] properties = ((Map<String, Object[]>)parsed).get("properties"); for (Object o : properties) { Map<String, Object> propertyInfo = (Map<String, Object>)o; String key = (String)propertyInfo.get("key"); String val = (String)propertyInfo.get("value"); String resource = (String)propertyInfo.get("resource"); System.err.println("k: " + key + " v: " + val + " r: " + resource); if (TEST_KEY.equals(key) && TEST_VAL.equals(val) && programSet.contains(resource)) { foundSetting = true; } } assertTrue(foundSetting); }
/** * @param in * Reader containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(Reader in, boolean stripOuterComment) throws IOException { return DEFAULT.parse(new ReaderSource(in),stripOuterComment); }
/** * @param s * String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return DEFAULT.parse(new StringSource(s),false); }
/** * @param s * String containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s, boolean stripOuterComment) { return DEFAULT.parse(new StringSource(s),stripOuterComment); }
/** * Convert JSON to Object * * @param json * The json to convert * @return The object */ public Object fromJSON(String json) { Source source = new StringSource(json); return parse(source); }
/** * @param s * String containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s, boolean stripOuterComment) { return DEFAULT.parse(new StringSource(s),stripOuterComment); }
/** * @param in * Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. * @throws IOException if unable to parse */ public static Object parse(Reader in) throws IOException { return DEFAULT.parse(new ReaderSource(in),false); }
/** * @param s * String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return DEFAULT.parse(new StringSource(s),false); }
/** * @param s * String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return DEFAULT.parse(new StringSource(s),false); }
/** * @param in * Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(Reader in) throws IOException { return DEFAULT.parse(new ReaderSource(in),false); }
/** * @param in * Reader containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(Reader in, boolean stripOuterComment) throws IOException { return DEFAULT.parse(new ReaderSource(in),stripOuterComment); }
/** * @param s * String containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s, boolean stripOuterComment) { return DEFAULT.parse(new StringSource(s),stripOuterComment); }
/** * Convert JSON to Object * * @param json * The json to convert * @return The object */ public Object fromJSON(String json) { Source source = new StringSource(json); return parse(source); }
/** * @param s * String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return DEFAULT.parse(new StringSource(s),false); }
/** * @param in * Reader containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. * @throws IOException if unable to parse */ public static Object parse(Reader in, boolean stripOuterComment) throws IOException { return DEFAULT.parse(new ReaderSource(in),stripOuterComment); }
/** * @param s * String containing JSON object or array. * @param stripOuterComment * If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s, boolean stripOuterComment) { return DEFAULT.parse(new StringSource(s),stripOuterComment); }
/** * Convert JSON to Object * * @param json * The json to convert * @return The object */ public Object fromJSON(String json) { Source source = new StringSource(json); return parse(source); }
/** * @param in * Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. * @throws IOException if unable to parse * @deprecated use {@link #parse(Reader)} */ @Deprecated public static Object parse(InputStream in) throws IOException { return DEFAULT.parse(new StringSource(IO.toString(in)),false); }
/** * @deprecated use {@link #parse(Reader)} * @param in * Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ @Deprecated public static Object parse(InputStream in) throws IOException { return DEFAULT.parse(new StringSource(IO.toString(in)),false); }