Search in sources :

Example 86 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class ListStringFieldTest_stream_array method test_empty.

public void test_empty() throws Exception {
    String text = "[[]]}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Model model = reader.readObject(Model.class);
    Assert.assertEquals(0, model.values.size());
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 87 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class ListStringFieldTest_stream_array method test_list.

public void test_list() throws Exception {
    String text = "[[\"a\",null,\"b\",\"ab\\\\c\\\"a\"]]";
    JSONReader reader = new JSONReader(new StringReader(text));
    Model model = reader.readObject(Model.class);
    Assert.assertEquals(4, model.values.size());
    Assert.assertEquals("a", model.values.get(0));
    Assert.assertEquals(null, model.values.get(1));
    Assert.assertEquals("b", model.values.get(2));
    Assert.assertEquals("ab\\c\"a", model.values.get(3));
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 88 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class ListStringFieldTest_stream_array_2 method test_list2.

public void test_list2() throws Exception {
    String text = "{\"values\":[\"a\",null,\"b\",\"ab\\\\c\"],\"values2\":[]}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Model model = reader.readObject(Model.class);
    Assert.assertEquals(4, model.values.size());
    Assert.assertEquals("a", model.values.get(0));
    Assert.assertEquals(null, model.values.get(1));
    Assert.assertEquals("b", model.values.get(2));
    Assert.assertEquals("ab\\c", model.values.get(3));
    Assert.assertEquals(0, model.values2.size());
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 89 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class JSONReader_string_1 method test_obj.

public void test_obj() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("\"abc\""));
    Assert.assertEquals("abc", reader.readString());
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 90 with JSONReader

use of com.alibaba.fastjson.JSONReader in project fastjson by alibaba.

the class JSONReader_typeRef method test_array_1.

public void test_array_1() throws Exception {
    JSONReader reader = new JSONReader(new StringReader("[[{\"id\":123}]]"));
    reader.startArray();
    List<VO> list = reader.readObject(new TypeReference<List<VO>>() {
    }.getType());
    Assert.assertEquals(123, list.get(0).getId());
    reader.endArray();
    reader.close();
}
Also used : StringReader(java.io.StringReader) TypeReference(com.alibaba.fastjson.TypeReference) JSONReader(com.alibaba.fastjson.JSONReader)

Aggregations

JSONReader (com.alibaba.fastjson.JSONReader)215 StringReader (java.io.StringReader)195 JSONException (com.alibaba.fastjson.JSONException)83 Map (java.util.Map)30 JSONScanner (com.alibaba.fastjson.parser.JSONScanner)11 IOException (java.io.IOException)5 JSONObject (com.alibaba.fastjson.JSONObject)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 JSONWriter (com.alibaba.fastjson.JSONWriter)3 File (java.io.File)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 JSONArray (com.alibaba.fastjson.JSONArray)2 TypeReference (com.alibaba.fastjson.TypeReference)2 VO (com.alibaba.json.bvt.writeAsArray.WriteAsArray_int_public.VO)2 StringWriter (java.io.StringWriter)2 Field (java.lang.reflect.Field)2 Random (java.util.Random)2 Model (com.alibaba.json.bvt.LongFieldTest_3_stream.Model)1