Search in sources :

Example 6 with JavaBeanSerializer

use of com.alibaba.fastjson.serializer.JavaBeanSerializer 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 7 with JavaBeanSerializer

use of com.alibaba.fastjson.serializer.JavaBeanSerializer 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 8 with JavaBeanSerializer

use of com.alibaba.fastjson.serializer.JavaBeanSerializer 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 9 with JavaBeanSerializer

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

the class TypeUtilsTest_castToJavaBean method test_bean_3.

public void test_bean_3() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("id", 123);
    PO vo = TypeUtils.castToJavaBean(map, PO.class);
    Assert.assertEquals(123, vo.id);
    SerializeWriter out = new SerializeWriter();
    try {
        SerializeConfig config = new SerializeConfig();
        JSONSerializer serializer = new JSONSerializer(out, config);
        config.put(PO.class, new JavaBeanSerializer(PO.class, Collections.singletonMap("id", (String) null)));
        serializer.write(vo);
        Assert.assertEquals("{}", out.toString());
    } finally {
        out.close();
    }
}
Also used : SerializeWriter(com.alibaba.fastjson.serializer.SerializeWriter) HashMap(java.util.HashMap) SerializeConfig(com.alibaba.fastjson.serializer.SerializeConfig) JavaBeanSerializer(com.alibaba.fastjson.serializer.JavaBeanSerializer) JSONSerializer(com.alibaba.fastjson.serializer.JSONSerializer)

Example 10 with JavaBeanSerializer

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

the class JavaBeanSerializerTest method test_error_s.

public void test_error_s() throws Exception {
    JSONException error = null;
    try {
        SerializeWriter out = new SerializeWriter();
        JavaBeanSerializer serializer = new JavaBeanSerializer(C.class);
        serializer.write(new JSONSerializer(out), new C(), 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)

Aggregations

JavaBeanSerializer (com.alibaba.fastjson.serializer.JavaBeanSerializer)15 JSONSerializer (com.alibaba.fastjson.serializer.JSONSerializer)10 SerializeWriter (com.alibaba.fastjson.serializer.SerializeWriter)8 HashMap (java.util.HashMap)6 Map (java.util.Map)5 SerializeConfig (com.alibaba.fastjson.serializer.SerializeConfig)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 IdentityHashMap (java.util.IdentityHashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 Collection (java.util.Collection)3 JSONException (com.alibaba.fastjson.JSONException)2 ObjectSerializer (com.alibaba.fastjson.serializer.ObjectSerializer)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FieldSerializer (com.alibaba.fastjson.serializer.FieldSerializer)1 IOException (java.io.IOException)1 Calendar (java.util.Calendar)1