Search in sources :

Example 21 with JSONReader

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

the class Issue72 method test_for_issue.

public void test_for_issue() throws Exception {
    InputStream is = Issue72.class.getClassLoader().getResourceAsStream("issue72.json");
    JSONReader reader = null;
    try {
        byte[] rowBatchBytes = null;
        byte[] fileBatchBytes = null;
        reader = new JSONReader(new InputStreamReader(is));
        reader.startArray();
        while (reader.hasNext()) {
            if (rowBatchBytes == null) {
                rowBatchBytes = reader.readObject(byte[].class);
            } else if (fileBatchBytes == null) {
                fileBatchBytes = reader.readObject(byte[].class);
            } else {
                throw new Exception("archive data json parse failed!");
            }
        }
        reader.endArray();
    } finally {
        IOUtils.close(reader);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JSONReader(com.alibaba.fastjson.JSONReader)

Example 22 with JSONReader

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

the class JSONReaderScannerTest_bytes method test_e.

public void test_e() throws Exception {
    VO vo = new VO();
    vo.setValue("ABC".getBytes("UTF-8"));
    String text = JSON.toJSONString(vo);
    JSONReader reader = new JSONReader(new StringReader(text));
    VO vo2 = reader.readObject(VO.class);
    Assert.assertEquals("ABC", new String(vo2.getValue()));
    reader.close();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 23 with JSONReader

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

the class JSONReaderScannerTest_enum method test_e.

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();
}
Also used : StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 24 with JSONReader

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

the class JSONReaderScannerTest_jsonobject method test_e.

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();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) StringReader(java.io.StringReader) JSONReader(com.alibaba.fastjson.JSONReader)

Example 25 with JSONReader

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

the class JSONReaderTest_array_array method test_read_1.

public void test_read_1() throws Exception {
    JSONReader reader = new JSONReader(new JSONScanner(text));
    reader.startArray();
    int count = 0;
    while (reader.hasNext()) {
        Object item = reader.readObject();
        Assert.assertEquals(JSONArray.class, item.getClass());
        count++;
    }
    Assert.assertEquals(10, count);
    reader.endArray();
    reader.close();
}
Also used : JSONScanner(com.alibaba.fastjson.parser.JSONScanner) 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