Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.JavaBeanSerializer


        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());
    }
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, 0);

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

        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, 0);
        } 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, 0);
        } catch (JSONException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
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

        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", "ID")));

            serializer.write(vo);

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

        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 {
View Full Code Here

    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected Collection<Object> getPropertyValues(final Object currentObject) {
        final Class<?> currentClass = currentObject.getClass();

        JavaBeanSerializer beanSerializer = getJavaBeanSerializer(currentClass);

        if (beanSerializer != null) {
            try {
                return beanSerializer.getFieldValues(currentObject);
            } catch (Exception e) {
                throw new JSONPathException("jsonpath error, path " + path, e);
            }
        }
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.