Package com.alibaba.fastjson

Examples of com.alibaba.fastjson.JSONReader


       
        reader.close();
    }

    public void test_1() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));

        reader.startObject();
        reader.readObject();

        Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception e) {
            error = e;
        }
        Assert.assertNotNull(error);
        reader.close();
    }
View Full Code Here


            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');
            }
            buf.append("\"}");
            JSONReader reader = new JSONReader(new StringReader(buf.toString()));
            reader.readObject();
            reader.close();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

import com.alibaba.fastjson.JSONReader;

public class JSONReaderScannerTest_enum extends TestCase {

    public void test_e() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{type:'AA'}"));
        VO vo2 = reader.readObject(VO.class);
        Assert.assertEquals(Type.AA, vo2.getType());
        reader.close();
    }
View Full Code Here

            buf.append("[{\"type\":\"");
            for (int i = 0; i < 8180; ++i) {
                buf.append('A');
            }
            buf.append("\\t");
            JSONReader reader = new JSONReader(new MyReader(buf.toString()));
            reader.readObject();
            reader.close();
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

import com.alibaba.fastjson.JSONReader;

public class JSONReaderScannerTest_jsonobject extends TestCase {

    public void test_e() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{\"type\\t\":'AA'}"));
        JSONObject vo = new JSONObject();
        reader.readObject(vo);
        Assert.assertEquals("AA", vo.get("type\t"));
        reader.close();
    }
View Full Code Here

    public void test_for_issue() throws Exception {
        String text = "{\"rec\":[{},{}]}";
       
        JsonStroe store = new JsonStroe();
       
        JSONReader reader = new JSONReader(new StringReader(text));
        reader.startObject();
       
        String key = reader.readString();
       
        Assert.assertEquals("rec", key);
        reader.startArray();
       
        List<KeyValue> list = new ArrayList<KeyValue>();
        while(reader.hasNext()) {
            KeyValue keyValue = reader.readObject(KeyValue.class);
            list.add(keyValue);
        }
        store.setRec(list);
       
        reader.endArray();
       
        reader.endObject();
       
        reader.close();
    }
View Full Code Here

import com.alibaba.fastjson.JSONReader;

public class JSONReader_obj_3 extends TestCase {

    public void test_obj() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));

        reader.startObject();
        Assert.assertEquals("id", reader.readString());
        Assert.assertEquals(Integer.valueOf(123), reader.readInteger());
        reader.endObject();

        reader.close();
    }
View Full Code Here

        reader.close();
    }

    public void test_obj_2() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{\"val\":{\"id\":123}}"));

        reader.startObject();

        Assert.assertEquals("val", reader.readString());

        reader.startObject();
        Assert.assertEquals("id", reader.readString());
        Assert.assertEquals(Integer.valueOf(123), reader.readInteger());
        reader.endObject();

        reader.endObject();

        reader.close();
    }
View Full Code Here

    String text = "[{},{},{},{},{} ,{},{},{},{},{}]";

    public void test_read() throws Exception {

        JSONReader reader = new JSONReader(new StringReader(text));
        reader.startArray();

        int count = 0;
        while (reader.hasNext()) {
            reader.readObject();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endArray();
        reader.close();
    }
View Full Code Here

        reader.endArray();
        reader.close();
    }

    public void test_read_1() throws Exception {
        JSONReader reader = new JSONReader(new JSONScanner(text));
        reader.startArray();

        int count = 0;
        while (reader.hasNext()) {
            reader.readObject();
            count++;
        }
        Assert.assertEquals(10, count);

        reader.endArray();
        reader.close();
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.JSONReader

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.