Search in sources :

Example 11 with JSONReaderScanner

use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.

the class JSONReaderScannerTest_chars method test_decimal.

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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser) BigDecimal(java.math.BigDecimal)

Example 12 with JSONReaderScanner

use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.

the class JSONReaderScannerTest_chars method test_float.

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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 13 with JSONReaderScanner

use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.

the class JSONReaderScannerTest_chars method test_double.

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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 14 with JSONReaderScanner

use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.

the class JSONReaderScannerTest_chars method test_long.

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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Example 15 with JSONReaderScanner

use of com.alibaba.fastjson.parser.JSONReaderScanner in project fastjson by alibaba.

the class JSONReaderScannerTest_enum method test_b.

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();
}
Also used : JSONReaderScanner(com.alibaba.fastjson.parser.JSONReaderScanner) DefaultJSONParser(com.alibaba.fastjson.parser.DefaultJSONParser)

Aggregations

JSONReaderScanner (com.alibaba.fastjson.parser.JSONReaderScanner)35 DefaultJSONParser (com.alibaba.fastjson.parser.DefaultJSONParser)34 JSONObject (com.alibaba.fastjson.JSONObject)14 Reader (java.io.Reader)14 StringReader (java.io.StringReader)14 JSONArray (com.alibaba.fastjson.JSONArray)5 BigDecimal (java.math.BigDecimal)3 LinkedHashMap (java.util.LinkedHashMap)1