Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.JSONReaderScanner


import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest_type extends TestCase {
  @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();
  }
View Full Code Here


public class JSONReaderScannerTest_chars extends TestCase {

    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();
    }
View Full Code Here

        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();
    }
View Full Code Here

        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();
    }
View Full Code Here

        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();
    }
View Full Code Here

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest_boolean extends TestCase {
  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();
  }
View Full Code Here

    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();
  }
View Full Code Here

import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest_matchField extends TestCase {

    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));
View Full Code Here

        }
        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());
View Full Code Here

public class JSONReaderScannerTest_negative extends TestCase {

    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();
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.parser.JSONReaderScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.