Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.DefaultJSONParser


   
   
    public void test_date2() {
        String text = "{\"date\":\"xxxxx\"}";
        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("xxxxx", json.get("date"));
    }
View Full Code Here


    }
   
    public void test_date3() {
        String text = "{\"1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\\t\":\"xxxxx\"}";
        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("xxxxx", json.get("1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\t"));
    }
View Full Code Here

    }
   
    public void test_date4() {
        String text = "{\"1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\\t\":\"xxxxx\"}";
        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("xxxxx", json.get("1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst1234567890abcdefghijklmnopqrst\t"));
    }
View Full Code Here

import com.alibaba.fastjson.parser.Feature;

public class FeatureParserTest extends TestCase {

    public void test_AllowSingleQuotes_0() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("{'a':3}");
        parser.config(Feature.AllowSingleQuotes, true);
        JSONObject json = (JSONObject) parser.parse();
        Assert.assertEquals(1, json.size());
        Assert.assertEquals(new Integer(3), (Integer) json.getInteger("a"));
    }
View Full Code Here

        Assert.assertEquals(1, json.size());
        Assert.assertEquals(new Integer(3), (Integer) json.getInteger("a"));
    }

    public void test_AllowSingleQuotes_1() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("{'a':'3'}");
        parser.config(Feature.AllowSingleQuotes, true);
        JSONObject json = (JSONObject) parser.parse();
        Assert.assertEquals(1, json.size());
        Assert.assertEquals("3", (String) json.get("a"));
    }
View Full Code Here

        Assert.assertEquals(1, json.size());
        Assert.assertEquals("3", (String) json.get("a"));
    }

    public void test_AllowUnQuotedFieldNames_0() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("{a:3}");
        parser.config(Feature.AllowUnQuotedFieldNames, true);
        JSONObject json = (JSONObject) parser.parse();
        Assert.assertEquals(1, json.size());
        Assert.assertEquals(new Integer(3), (Integer) json.getInteger("a"));
    }
View Full Code Here

    }

    public void test_error_0() throws Exception {
        JSONException error = null;
        try {
            DefaultJSONParser parser = new DefaultJSONParser("{'a':3}");
            parser.config(Feature.AllowSingleQuotes, false);
            parser.parse();
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

    }

    public void test_error_1() throws Exception {
        JSONException error = null;
        try {
            DefaultJSONParser parser = new DefaultJSONParser("{\"a\":'3'}");
            parser.config(Feature.AllowSingleQuotes, false);
            parser.parse();
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

    }

    public void test_error_2() throws Exception {
        JSONException error = null;
        try {
            DefaultJSONParser parser = new DefaultJSONParser("{a:3}");
            parser.config(Feature.AllowUnQuotedFieldNames, false);
            parser.parse();
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

import com.alibaba.fastjson.parser.Feature;

public class FeatureTest extends TestCase {

    public void test_default() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser("");

        Assert.assertEquals(false, parser.isEnabled(Feature.AllowComment));
        Assert.assertEquals(true, parser.isEnabled(Feature.AllowSingleQuotes));
        Assert.assertEquals(true, parser.isEnabled(Feature.AllowUnQuotedFieldNames));
        Assert.assertEquals(true, parser.isEnabled(Feature.AutoCloseSource));
        Assert.assertEquals(true, parser.isEnabled(Feature.InternFieldNames));
    }
View Full Code Here

TOP

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

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.