Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.DefaultJSONParser.parseObject()


    }
   
    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


public class JSONReaderScannerTest_enum extends TestCase {

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

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

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

        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 static class VO {
View Full Code Here

import com.alibaba.fastjson.parser.JSONReaderScanner;

public class JSONReaderScannerTest extends TestCase {
  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 {
View Full Code Here

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

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

        char[] chars = text.toCharArray();
        DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);

        JSONException error = null;
        try {
            parser.parseObject();
        } catch (JSONException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

    public void test_date() {
        String text = "{\"date\":\"2011-01-09T13:49:53.254\"}";
        char[] chars = text.toCharArray();
        DefaultJSONParser parser = new DefaultJSONParser(chars, chars.length, ParserConfig.getGlobalInstance(), 0);
        parser.config(Feature.AllowISO8601DateFormat, true);
        JSONObject json = parser.parseObject();
        Assert.assertEquals(new Date(1294552193254L), json.get("date"));
    }
   
   
    public void test_date2() {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.