Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.JSONSerializer.config()


    public void test_9_s() throws Exception {
        JSONSerializer serializer = new JSONSerializer();

        serializer.config(SerializerFeature.QuoteFieldNames, false);
        Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.QuoteFieldNames));
        serializer.config(SerializerFeature.WriteMapNullValue, false);
        Assert.assertEquals(false, serializer.isEnabled(SerializerFeature.WriteMapNullValue));

        SerializeWriter out = new SerializeWriter();

        Map map = new LinkedHashMap();
View Full Code Here


    public static final String toJSONString(Object object) {
        SerializeWriter out = new SerializeWriter();

        try {
            JSONSerializer serializer = new JSONSerializer(out);
            serializer.config(SerializerFeature.SortField, false);
            serializer.config(SerializerFeature.UseSingleQuotes, true);

            serializer.write(object);

            return out.toString();
View Full Code Here

        SerializeWriter out = new SerializeWriter();

        try {
            JSONSerializer serializer = new JSONSerializer(out);
            serializer.config(SerializerFeature.SortField, false);
            serializer.config(SerializerFeature.UseSingleQuotes, true);

            serializer.write(object);

            return out.toString();
        } catch (StackOverflowError e) {
View Full Code Here

                   
                    return value;
                }
            });
            for (com.alibaba.fastjson.serializer.SerializerFeature feature : features) {
                serializer.config(feature, true);
            }

            serializer.write(object);

            return out.toString();
View Full Code Here

    public void test_0() throws Exception {
        JSONSerializer serializer = new JSONSerializer();

        int size = serializer.getMapping().size();
        serializer.config(SerializerFeature.WriteEnumUsingToString, false);
        serializer.write(Type.A);

        Assert.assertTrue(size < serializer.getMapping().size());

        Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
View Full Code Here

        Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
    }

    public void test_1() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.config(SerializerFeature.WriteEnumUsingToString, false);
        serializer.write(new A(Type.B));

        Assert.assertEquals("{\"type\":" + Integer.toString(Type.B.ordinal()) + "}", serializer.getWriter().toString());

        A a = JSON.parseObject(serializer.getWriter().toString(), A.class);
View Full Code Here

        Assert.assertEquals("{}", serializer.getWriter().toString());
    }

    public void test_3() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        serializer.config(SerializerFeature.WriteEnumUsingToString, true);
        serializer.write(new A(Type.B));

        Assert.assertEquals("{\"type\":\"B\"}", serializer.getWriter().toString());

        A a = JSON.parseObject(serializer.getWriter().toString(), A.class);
View Full Code Here

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.UseISO8601DateFormat, true);
        Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
        serializer.write(new Date(1294552193254L));

        Assert.assertEquals("\"2011-01-09T13:49:53.254\"", out.toString());
    }
View Full Code Here

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.UseISO8601DateFormat, true);
        Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
        serializer.write(new Date(1294552193000L));

        Assert.assertEquals("\"2011-01-09T13:49:53\"", out.toString());
    }
View Full Code Here

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.UseISO8601DateFormat, true);
        Assert.assertEquals(true, serializer.isEnabled(SerializerFeature.UseISO8601DateFormat));
        serializer.write(new Date(1294502400000L));

        Assert.assertEquals("\"2011-01-09\"", out.toString());
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.