Package com.alibaba.fastjson.parser

Examples of com.alibaba.fastjson.parser.DefaultExtJSONParser


import com.alibaba.json.test.entity.TestEntity;

public class DefaultExtJSONParserTest_1 extends TestCase {

    public void test_0() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("{\"f1\":true}");
        TestEntity entity = parser.parseObject(TestEntity.class);
        Assert.assertEquals(true, entity.isF1());
    }
View Full Code Here


        TestEntity entity = parser.parseObject(TestEntity.class);
        Assert.assertEquals(true, entity.isF1());
    }

    public void test_1() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("{\"f2\":true}");
        TestEntity entity = parser.parseObject(TestEntity.class);
        Assert.assertEquals(Boolean.TRUE, entity.getF2());
    }
View Full Code Here

        String text = JSON.toJSONString(a);
        System.out.println(text);

        TestEntity b = new TestEntity();
        {
            DefaultExtJSONParser parser = new DefaultExtJSONParser(text);
            parser.parseObject(b);
        }

        Assert.assertEquals("f1", a.isF1(), b.isF1());
        Assert.assertEquals("f2", a.getF2(), b.getF2());
        Assert.assertEquals("f3", a.getF3(), b.getF3());
View Full Code Here

import com.alibaba.fastjson.parser.JSONToken;

public class DefaultExtJSONParser_parseArray extends TestCase {

    public void test_0() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("[1,2,,,3]");
        List list = new ArrayList();
        parser.parseArray(int.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
    }
View Full Code Here

        parser.parseArray(int.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
    }

    public void test_1() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("[1,2,3]");
        parser.config(Feature.AllowArbitraryCommas, true);
        List list = new ArrayList();
        parser.parseArray(int.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
    }
View Full Code Here

        parser.parseArray(int.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
    }

    public void test_2() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("['1','2','3']");
        parser.config(Feature.AllowArbitraryCommas, true);
        List list = new ArrayList();
        parser.parseArray(String.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
        Assert.assertEquals("1", list.get(0));
    }
View Full Code Here

        Assert.assertEquals("[1, 2, 3]", list.toString());
        Assert.assertEquals("1", list.get(0));
    }

    public void test_3() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("[1,2,3]");
        parser.config(Feature.AllowArbitraryCommas, true);
        List list = new ArrayList();
        parser.parseArray(BigDecimal.class, list);
        Assert.assertEquals("[1, 2, 3]", list.toString());
        Assert.assertEquals(new BigDecimal("1"), list.get(0));
    }
View Full Code Here

        Assert.assertEquals("[1, 2, 3]", list.toString());
        Assert.assertEquals(new BigDecimal("1"), list.get(0));
    }

    public void test_4() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("[1,2,3,null]");
        parser.config(Feature.AllowArbitraryCommas, true);
        List list = new ArrayList();
        parser.parseArray(BigDecimal.class, list);
        Assert.assertEquals("[1, 2, 3, null]", list.toString());
        Assert.assertEquals(new BigDecimal("1"), list.get(0));
    }
View Full Code Here

        Assert.assertEquals("[1, 2, 3, null]", list.toString());
        Assert.assertEquals(new BigDecimal("1"), list.get(0));
    }

    public void test_5() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("[1,2,3,null]");
        Object[] array = parser.parseArray(new Type[] { Integer.class, BigDecimal.class, Long.class, String.class });
        Assert.assertEquals(new Integer(1), array[0]);
        Assert.assertEquals(new BigDecimal("2"), array[1]);
        Assert.assertEquals(new Long(3), array[2]);
        Assert.assertEquals(null, array[3]);
    }
View Full Code Here

        Assert.assertEquals(new Long(3), array[2]);
        Assert.assertEquals(null, array[3]);
    }

    public void test_error() throws Exception {
        DefaultExtJSONParser parser = new DefaultExtJSONParser("{}");
        Exception error = null;
        try {
            parser.parseArray(new ArrayList());
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

TOP

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

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.