Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.JavaBeanSerializer


import com.alibaba.fastjson.serializer.JavaBeanSerializer;

public class JavaBeanSerializerTest2 extends TestCase {

    public void test_0() throws Exception {
        new JavaBeanSerializer(A.class, Collections.<String, String> emptyMap());
    }
View Full Code Here


        User user = new User();
        user.setId(123);
        user.setName("毛头");

        SerializeConfig mapping = new SerializeConfig();
        mapping.put(User.class, new JavaBeanSerializer(User.class, "id"));

        JSONSerializer serializer = new JSONSerializer(mapping);
        serializer.write(user);
        String jsonString = serializer.toString();
View Full Code Here

        User user = new User();
        user.setId(123);
        user.setName("毛头");

        SerializeConfig mapping = new SerializeConfig();
        mapping.put(User.class, new JavaBeanSerializer(User.class, Collections.singletonMap("id", "uid")));

        JSONSerializer serializer = new JSONSerializer(mapping);
        serializer.write(user);
        String jsonString = serializer.toString();
View Full Code Here

        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);

        Assert.assertEquals("{\"l0\":[\"A\",\"B\"]}", out.toString());
    }
View Full Code Here

        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);

        Assert.assertEquals("{\"l0\":[\"A\",\"B\"],\"l1\":[]}", out.toString());
    }
View Full Code Here

    }

    public void test_2_s() throws Exception {
        SerializeWriter out = new SerializeWriter();

        JavaBeanSerializer serializer = new JavaBeanSerializer(F.class);
        serializer.write(new JSONSerializer(out), new F(new E(123)), null, null);

        Assert.assertEquals("{\"e\":{\"id\":123}}", out.toString());
    }
View Full Code Here

    }

    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);

        for (FieldSerializer getter : serializer.getGetters()) {
            getter.getName();
            getter.getMethod();
        }

        Assert.assertEquals("{}", out.toString());
View Full Code Here

    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);
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

    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);
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
View Full Code Here

        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());
    }
View Full Code Here

TOP

Related Classes of com.alibaba.fastjson.serializer.JavaBeanSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.