public void test_1() throws Exception { JSONObject res = new JSONObject(); res.put("a", 1); res.put("b", 2); res.put("c", 3); String[] tests = { "{ 'a':1, 'b':2, 'c':3 }", "{ 'a':1,,'b':2, 'c':3 }", "{,'a':1, 'b':2, 'c':3 }", "{'a':1, 'b':2, 'c':3,,}", "{,,'a':1,,,,'b':2,'c':3,,,,,}", }; for (String t : tests) { DefaultJSONParser ext = new DefaultJSONParser(t); ext.config(Feature.AllowArbitraryCommas, true); JSONObject extRes = ext.parseObject(); Assert.assertEquals(res, extRes); DefaultJSONParser basic = new DefaultJSONParser(t); basic.config(Feature.AllowArbitraryCommas, true); JSONObject basicRes = basic.parseObject(); Assert.assertEquals(res, basicRes); } }
public void test_0() throws Exception { List<?> res = Arrays.asList(1, 2, 3); String[] tests = { "[1,2,3]", "[1,,2,3]", "[1,2,,,3]", "[1 2,,,3]", "[1 2 3]", "[1, 2, 3,,]", "[,,1, 2, 3,,]", }; for (String t : tests) { DefaultJSONParser ext = new DefaultJSONParser(t); ext.config(Feature.AllowArbitraryCommas, true); List<Object> extRes = ext.parseArray(Object.class); Assert.assertEquals(res, extRes); DefaultJSONParser basic = new DefaultJSONParser(t); basic.config(Feature.AllowArbitraryCommas, true); List<Object> basicRes = new ArrayList<Object>(); basic.parseArray(basicRes); Assert.assertEquals(res, basicRes); } }
public void test_error_3() throws Exception { JSONException error = null; try { DefaultJSONParser parser = new DefaultJSONParser("{"); parser.config(Feature.AllowUnQuotedFieldNames, true); parser.parseObject(A.class); } catch (JSONException e) { error = e; } Assert.assertNotNull(error); }
public void test_error_6() throws Exception { JSONException error = null; try { DefaultJSONParser parser = new DefaultJSONParser("{'a':3}"); parser.config(Feature.AllowSingleQuotes, false); parser.parseObject(A.class); } catch (JSONException e) { error = e; } Assert.assertNotNull(error); }
public void test_2() throws Exception { A res = new A(); res.setA(1); res.setB(2); res.setC(3); String[] tests = { "{ 'a':1, 'b':2, 'c':3 }", "{ 'a':1,,'b':2, 'c':3 }", "{,'a':1, 'b':2, 'c':3 }", "{'a':1, 'b':2, 'c':3,,}", "{,,'a':1,,,,'b':2,,'c':3,,,,,}", }; for (String t : tests) { DefaultJSONParser ext = new DefaultJSONParser(t); ext.config(Feature.AllowArbitraryCommas, true); A extRes = ext.parseObject(A.class); Assert.assertEquals(res, extRes); } }
public void test_4() throws Exception { DefaultJSONParser parser = new DefaultJSONParser("{a:3}"); parser.config(Feature.AllowUnQuotedFieldNames, true); LinkedHashMap a = parser.parseObject(LinkedHashMap.class); Assert.assertEquals(3, a.get("a")); }
public void test_1() throws Exception { DefaultJSONParser parser = new DefaultJSONParser("{a:3}"); parser.config(Feature.AllowUnQuotedFieldNames, true); A a = parser.parseObject(A.class); Assert.assertEquals(3, a.getA()); }
public void test_0() throws Exception { DefaultJSONParser parser = new DefaultJSONParser("{'a':3}"); parser.config(Feature.AllowSingleQuotes, true); A a = parser.parseObject(A.class); Assert.assertEquals(3, a.getA()); }
public final Object decode(String text) { ParserConfig config = new ParserConfig(); DefaultJSONParser parser = new DefaultJSONParser(text, config); parser.config(Feature.DisableCircularReferenceDetect, true); return parser.parse(); }
public <T> Collection<T> decodeArray(String text, Class<T> clazz) throws Exception { ParserConfig config = new ParserConfig(); DefaultJSONParser parser = new DefaultJSONParser(text, config); parser.config(Feature.DisableCircularReferenceDetect, true); return parser.parseArray(clazz); }
public <T> T decodeObject(String text, Class<T> clazz) { ParserConfig config = new ParserConfig(); DefaultJSONParser parser = new DefaultJSONParser(text, config); parser.config(Feature.DisableCircularReferenceDetect, true); return parser.parseObject(clazz); }