Search in sources :

Example 1 with JSONReader

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

the class EnumFieldTest method test_error.

public void test_error() throws Exception {
    Exception error = null;
    try {
        JSONReader read = new JSONReader(new StringReader("{\"value\":\"a\\b\"}"));
        read.readObject(Model.class);
    } 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 2 with JSONReader

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

the class EnumFieldTest method test_1.

public void test_1() throws Exception {
    JSONReader read = new JSONReader(new StringReader("{\"value\":\"A\",\"value1\":\"B\"}"));
    Model model = read.readObject(Model.class);
    Assert.assertEquals(Type.A, model.value);
    Assert.assertEquals(Type.B, model.value1);
    read.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 3 with JSONReader

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

the class EnumFieldTest2 method test_error_nul.

public void test_error_nul() throws Exception {
    Exception error = null;
    try {
        JSONReader read = new JSONReader(new StringReader("[nul"));
        read.config(Feature.SupportArrayToBean, true);
        Model model = read.readObject(Model.class);
        read.readObject(Model.class);
    } 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 4 with JSONReader

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

the class EnumFieldTest2 method test_2.

public void test_2() throws Exception {
    JSONReader read = new JSONReader(new StringReader("[null,null]"));
    read.config(Feature.SupportArrayToBean, true);
    Model model = read.readObject(Model.class);
    Assert.assertEquals(null, model.value);
    Assert.assertEquals(null, model.value1);
    read.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 5 with JSONReader

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

the class EnumFieldTest2 method test_error_nu.

public void test_error_nu() throws Exception {
    Exception error = null;
    try {
        JSONReader read = new JSONReader(new StringReader("[nu"));
        read.config(Feature.SupportArrayToBean, true);
        Model model = read.readObject(Model.class);
        read.readObject(Model.class);
    } 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)

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