Search in sources :

Example 81 with JSONReader

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

the class ListStringFieldTest_stream_array method test_error_n.

public void test_error_n() throws Exception {
    String text = "[n";
    JSONReader reader = new JSONReader(new StringReader(text));
    Exception error = null;
    try {
        reader.readObject(Model.class);
        reader.close();
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : StringReader(java.io.StringReader) JSONException(com.alibaba.fastjson.JSONException) JSONReader(com.alibaba.fastjson.JSONReader) JSONException(com.alibaba.fastjson.JSONException)

Example 82 with JSONReader

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

the class ListStringFieldTest_stream_array method test_map_empty.

public void test_map_empty() throws Exception {
    String text = "{\"model\":[[]]}";
    JSONReader reader = new JSONReader(new StringReader(text));
    Map<String, Model> map = reader.readObject(new TypeReference<Map<String, Model>>() {
    });
    Model model = (Model) map.get("model");
    Assert.assertEquals(0, model.values.size());
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader) Map(java.util.Map)

Example 83 with JSONReader

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

the class ListStringFieldTest_stream_array method test_error_null.

public void test_error_null() throws Exception {
    String text = "[null";
    JSONReader reader = new JSONReader(new StringReader(text));
    Exception error = null;
    try {
        reader.readObject(Model.class);
        reader.close();
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : StringReader(java.io.StringReader) JSONException(com.alibaba.fastjson.JSONException) JSONReader(com.alibaba.fastjson.JSONReader) JSONException(com.alibaba.fastjson.JSONException)

Example 84 with JSONReader

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

the class ListStringFieldTest_stream_array method test_error_2.

public void test_error_2() throws Exception {
    String text = "{\"model\":[[][";
    JSONReader reader = new JSONReader(new StringReader(text));
    Exception error = null;
    try {
        reader.readObject(new TypeReference<Map<String, Model>>() {
        });
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : StringReader(java.io.StringReader) JSONException(com.alibaba.fastjson.JSONException) JSONReader(com.alibaba.fastjson.JSONReader) Map(java.util.Map) JSONException(com.alibaba.fastjson.JSONException)

Example 85 with JSONReader

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

the class ListStringFieldTest_stream_array method test_error_3.

public void test_error_3() throws Exception {
    String text = "{\"model\":[[]}[";
    JSONReader reader = new JSONReader(new StringReader(text));
    Exception error = null;
    try {
        reader.readObject(new TypeReference<Map<String, Model>>() {
        });
    } catch (JSONException ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
}
Also used : StringReader(java.io.StringReader) JSONException(com.alibaba.fastjson.JSONException) JSONReader(com.alibaba.fastjson.JSONReader) Map(java.util.Map) JSONException(com.alibaba.fastjson.JSONException)

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