Search in sources :

Example 1 with JSONStreamAware

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

the class JSONSerializerTest method test_error.

public void test_error() throws Exception {
    JSONException error = null;
    try {
        StringWriter out = new StringWriter();
        JSONSerializer serializer = new JSONSerializer();
        serializer.write(new JSONStreamAware() {

            public void writeJSONString(Appendable out) throws IOException {
                throw new IOException();
            }
        });
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : StringWriter(java.io.StringWriter) JSONException(com.alibaba.fastjson.JSONException) IOException(java.io.IOException) JSONStreamAware(com.alibaba.fastjson.JSONStreamAware) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 2 with JSONStreamAware

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

the class JSONSerializerTest method test_4.

public void test_4() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new JSONStreamAware() {

        public void writeJSONString(Appendable out) throws IOException {
            out.append("abc");
        }
    });
    Assert.assertEquals("abc", serializer.getWriter().toString());
}
Also used : IOException(java.io.IOException) JSONStreamAware(com.alibaba.fastjson.JSONStreamAware) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

JSONStreamAware (com.alibaba.fastjson.JSONStreamAware)2 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)2 IOException (java.io.IOException)2 JSONException (com.alibaba.fastjson.JSONException)1 StringWriter (java.io.StringWriter)1