public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append(i + ".0"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); JSONArray array = (JSONArray) parser.parse(); for (int i = 0; i < array.size(); ++i) { BigDecimal value = new BigDecimal(i + ".0"); Assert.assertEquals(value, array.get(i)); } }
public void test_scanFloat() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append("{\"id\":" + i + ".0}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertTrue((float) i == array.get(i).getId()); } parser.close(); }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append("{\"id\":" + i + "}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(i, array.get(i).getId()); } }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 10; ++i) { if (i != 0) { buf.append(','); } // 1000000000000 // buf.append("\"" + i + "\""); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); JSONArray array = (JSONArray) parser.parse(); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(Integer.toString(i), array.get(i)); } }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append(i); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); JSONArray array = (JSONArray) parser.parse(); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(i, ((Integer) array.get(i)).intValue()); } }
public void test_scanFloat() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append("{\"id\":" + i + ".0}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertTrue((double) i == array.get(i).getId()); } parser.close(); }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 10; ++i) { if (i != 0) { buf.append(','); } //1000000000000 // buf.append("{\"id\":\"" + i + "\"}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(Integer.toString(i), array.get(i).getId()); } }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 10; ++i) { if (i != 0) { buf.append(','); } // 1000000000000 // buf.append("{\"id\":\"" + i + "\"}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); JSONArray array = (JSONArray) parser.parse(); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(Integer.toString(i), array.getJSONObject(i).get("id")); } }
public void test_scanFloat() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 1024; ++i) { if (i != 0) { buf.append(','); } buf.append("{\"id\":" + i + ".0}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertTrue(Integer.toString(i), (double) i == array.get(i).getId()); } parser.close(); }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 10; ++i) { if (i != 0) { buf.append(','); } //1000000000000 // buf.append("{\"id\":[\"" + i + "\",\"" + (10000 + i) + "\"]}"); } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { Assert.assertEquals(2, array.get(i).getId().size()); Assert.assertEquals(Integer.toString(i), array.get(i).getId().get(0)); Assert.assertEquals(Integer.toString(10000 + i), array.get(i).getId().get(1)); } }
public void test_double() throws Exception { char[] chars = "{\"value\":-3.5D}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(-3.5D == ((Double) json.get("value")).doubleValue()); parser.close(); }
public void test_float() throws Exception { char[] chars = "{\"value\":-3.5F}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(-3.5F == ((Float) json.get("value")).doubleValue()); parser.close(); }
public void test_decimal() throws Exception { char[] chars = "{\"value\":-3.5}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertEquals(new BigDecimal("-3.5"), json.get("value")); parser.close(); }
public void test_long() throws Exception { char[] chars = "{\"value\":-3L}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(-3L == ((Long) json.get("value")).longValue()); parser.close(); }
@SuppressWarnings("rawtypes") public void test_true() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"@type\":\"java.util.LinkedHashMap\",\"name\":\"张三\"}")); LinkedHashMap json = (LinkedHashMap) parser.parse(); Assert.assertEquals("张三", json.get("name")); parser.close(); }
public void test_double() throws Exception { char[] chars = "{\"value\":3.5D}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(3.5D == ((Double) json.get("value")).doubleValue()); parser.close(); }
public void test_float() throws Exception { char[] chars = "{\"value\":3.5F}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(3.5F == ((Float) json.get("value")).doubleValue()); parser.close(); }
public void test_decimal() throws Exception { char[] chars = "{\"value\":3.5}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertEquals(new BigDecimal("3.5"), json.get("value")); parser.close(); }
public void test_long() throws Exception { char[] chars = "{\"value\":3L}".toCharArray(); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(chars, chars.length)); JSONObject json = parser.parseObject(); Assert.assertTrue(3L == ((Long) json.get("value")).longValue()); parser.close(); }
public void test_true() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"items\":[{}],\"value\":{}}")); VO vo = parser.parseObject(VO.class); Assert.assertNotNull(vo.getValue()); Assert.assertNotNull(vo.getItems()); Assert.assertEquals(1, vo.getItems().size()); Assert.assertNotNull(vo.getItems().get(0)); parser.close(); }
public void test_scanInt() throws Exception { StringBuffer buf = new StringBuffer(); buf.append('['); for (int i = 0; i < 10; ++i) { if (i != 0) { buf.append(','); } //1000000000000 // if (i % 2 == 0) { buf.append("{\"id\":true}"); } else { buf.append("{\"id\":false}"); } } buf.append(']'); Reader reader = new StringReader(buf.toString()); JSONReaderScanner scanner = new JSONReaderScanner(reader); DefaultJSONParser parser = new DefaultJSONParser(scanner); List<VO> array = parser.parseArray(VO.class); for (int i = 0; i < array.size(); ++i) { if (i % 2 == 0) { Assert.assertEquals(true, array.get(i).getId()); } else { Assert.assertEquals(false, array.get(i).getId()); } } }
public void test_reader() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"date\":\"2012/04-01\"}", 0)); parser.setDateFormat("yyyy/MM-dd"); VO vo = parser.parseObject(VO.class); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM-dd", JSON.defaultLocale); dateFormat.setTimeZone(JSON.defaultTimeZone); Assert.assertEquals(dateFormat.parse("2012/04-01"), vo.getDate()); parser.close(); }
public void test_0() throws Exception { String jsonWithComment = "{ /*tes****\n\r\n*t*/\"a\":1 /*****test88888*****/ /*test*/ , /*test*/ //test\n //est\n \"b\":2}"; JSONObject object = JSON.parseObject(jsonWithComment, Feature.AllowComment, Feature.OrderedField); System.out.println(object.toJSONString()); Assert.assertEquals("{\"a\":1,\"b\":2}",object.toJSONString()); DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner(jsonWithComment, Feature.AllowComment.getMask() | Feature.OrderedField.getMask())); JSONObject object1 = parser.parseObject(); Assert.assertEquals("{\"a\":1,\"b\":2}",object1.toJSONString()); System.out.println(object1.toJSONString()); }
public JSONReader(Reader reader, Feature... features){ this(new JSONReaderScanner(reader)); for (Feature feature : features) { this.config(feature, true); } }
public void test_singleQuote() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{'name':'张三\\'\\n\\r\\\"'}")); JSONObject json = parser.parseObject(); Assert.assertEquals("张三\'\n\r\"", json.get("name")); parser.close(); }
public void test_doubleQuote() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":\"张三\\'\\n\\r\\\"\"}")); JSONObject json = parser.parseObject(); Assert.assertEquals("张三\'\n\r\"", json.get("name")); parser.close(); }
public void test_doubleQuote_2() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{name:\"张三\\'\\n\\r\\\"\"}")); JSONObject json = parser.parseObject(); Assert.assertEquals("张三\'\n\r\"", json.get("name")); parser.close(); }
public void test_true() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":true}")); JSONObject json = parser.parseObject(); Assert.assertEquals(Boolean.TRUE, json.get("name")); parser.close(); }
public void test_false() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"name\":false}")); JSONObject json = parser.parseObject(); Assert.assertEquals(Boolean.FALSE, json.get("name")); parser.close(); }
public void test_a() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"A\"}")); VO vo = parser.parseObject(VO.class); Assert.assertEquals(Type.A, vo.getType()); parser.close(); }
public void test_b() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"B\"}")); VO vo = parser.parseObject(VO.class); Assert.assertEquals(Type.B, vo.getType()); parser.close(); }
public void test_c() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"C\"}")); VO vo = parser.parseObject(VO.class); Assert.assertEquals(Type.C, vo.getType()); parser.close(); }
public void test_x() throws Exception { DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}")); VO vo = parser.parseObject(VO.class); Assert.assertEquals(Type.XXXXXXXXXXXXXXXXXXXXXXXX, vo.getType()); parser.close(); }
public void test_ident_3() throws Exception { JSONReaderScanner lexer = new JSONReaderScanner("\uFEFF123"); lexer.nextIdent(); org.junit.Assert.assertEquals(JSONToken.LITERAL_INT, lexer.token()); lexer.close(); }
public JSONReader(Reader reader) { this(new JSONReaderScanner(reader)); }
public JSONReader(Reader reader){ this(new JSONReaderScanner(reader)); }
@Override public ResumableParser createResumableParser(Reader reader, SurfingContext context) { return new FastJsonResumableParser(new JSONReaderScanner(reader), context, new StaticPrimitiveHolder()); }