Search in sources :

Example 91 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class ObjectArraySerializerTest method test_0.

public void test_0() throws Exception {
    SerializeWriter out = new SerializeWriter(1);
    JSONSerializer.write(out, new Object[] { "a12", "b34" });
    Assert.assertEquals("[\"a12\",\"b34\"]", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 92 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class PrimitiveTest method test_0_s.

public void test_0_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer.write(out, (byte) 1);
    Assert.assertEquals("1", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 93 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class PrimitiveTest method test_5_s.

public void test_5_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    JSONSerializer.write(out, new boolean[] {});
    Assert.assertEquals("[]", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter)

Example 94 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class SerializeWriterTest_16 method test_writer_1.

public void test_writer_1() throws Exception {
    StringWriter strOut = new StringWriter();
    SerializeWriter out = new SerializeWriter(strOut, 14);
    out.config(SerializerFeature.BrowserCompatible, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        VO vo = new VO();
        vo.setValue("abcd\t");
        serializer.write(vo);
    } finally {
        out.close();
    }
    Assert.assertEquals("{value:\"abcd\\t\"}", strOut.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) StringWriter(java.io.StringWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 95 with SerializeWriter

use of com.alibaba.fastjson.serializer.SerializeWriter in project fastjson by alibaba.

the class SerializeWriterTest_17 method test_direct.

public void test_direct() throws Exception {
    SerializeWriter out = new SerializeWriter(6);
    out.config(SerializerFeature.QuoteFieldNames, true);
    try {
        JSONSerializer serializer = new JSONSerializer(out);
        VO vo = new VO();
        vo.setValue(123456789);
        serializer.write(vo);
        Assert.assertEquals("{\"value\":123456789}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)345 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)206 PropertyFilter (com.alibaba.fastjson.serializer.PropertyFilter)54 HashMap (java.util.HashMap)47 StringWriter (java.io.StringWriter)38 NameFilter (com.alibaba.fastjson.serializer.NameFilter)36 ValueFilter (com.alibaba.fastjson.serializer.ValueFilter)19 ArrayList (java.util.ArrayList)12 ListSerializer (com.alibaba.fastjson.serializer.ListSerializer)11 MapSerializer (com.alibaba.fastjson.serializer.MapSerializer)10 JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)8 Date (java.util.Date)8 Map (java.util.Map)8 CollectionCodec (com.alibaba.fastjson.serializer.CollectionCodec)6 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)6 LinkedHashMap (java.util.LinkedHashMap)6 JSONException (com.alibaba.fastjson.JSONException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 A (com.alibaba.json.bvt.serializer.filters.PropertyFilterTest.A)4 JSONObject (com.alibaba.fastjson.JSONObject)3