Search in sources :

Example 16 with SerializeWriter

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

the class JavaBeanSerializerTest method test_0_s.

public void test_0_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    A a = new A();
    a.getL0().add("A");
    a.getL0().add("B");
    JavaBeanSerializer serializer = new JavaBeanSerializer(A.class);
    serializer.write(new JSONSerializer(out), a, null, null, 0);
    Assert.assertEquals("{\"l0\":[\"A\",\"B\"]}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 17 with SerializeWriter

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

the class JavaBeanSerializerTest method test_error_1_s.

public void test_error_1_s() throws Exception {
    JSONException error = null;
    try {
        SerializeWriter out = new SerializeWriter();
        JavaBeanSerializer serializer = new JavaBeanSerializer(D.class);
        serializer.write(new JSONSerializer(out), new D(), null, null, 0);
    } catch (JSONException e) {
        error = e;
    }
    Assert.assertNotNull(error);
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JSONException(com.alibaba.fastjson.JSONException) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 18 with SerializeWriter

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

the class JavaBeanSerializerTest method test_1_s.

public void test_1_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    B a = new B();
    a.getL0().add("A");
    a.getL0().add("B");
    JavaBeanSerializer serializer = new JavaBeanSerializer(B.class);
    serializer.write(new JSONSerializer(out), a, null, null, 0);
    Assert.assertEquals("{\"l0\":[\"A\",\"B\"],\"l1\":[]}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 19 with SerializeWriter

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

the class JavaBeanSerializerTest method test_3_s.

public void test_3_s() throws Exception {
    SerializeWriter out = new SerializeWriter();
    JavaBeanSerializer serializer = new JavaBeanSerializer(F.class);
    serializer.write(new JSONSerializer(out), new F(null), null, null, 0);
    Assert.assertEquals("{}", out.toString());
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 20 with SerializeWriter

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

the class ListSerializerTest method test_8_s.

public void test_8_s() throws Exception {
    SerializeWriter out = new SerializeWriter(SerializerFeature.WriteClassName);
    ListSerializer listSerializer = new ListSerializer();
    List<Object> list = new ArrayList<Object>();
    list.add(1L);
    list.add(1453964515792017682L);
    listSerializer.write(new JSONSerializer(out), list, null, null, 0);
    Assert.assertEquals("[1L,1453964515792017682L]", out.toString());
}
Also used : ListSerializer(com.alibaba.fastjson.serializer.ListSerializer) SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) ArrayList(java.util.ArrayList) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Aggregations

SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)344 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)205 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