Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.SerializeWriter


        out.writeFieldValue(',', "name", "\t\n \b\n\r\f\\ \"");
        Assert.assertEquals(",\"name\":\"\t\\n \\b\\n\\r\\f\\\\ \\\"\"", out.toString());
    }
   
    public void test_5() throws Exception {
        SerializeWriter out = new SerializeWriter(1000);
        out.config(SerializerFeature.QuoteFieldNames, true);
        out.config(SerializerFeature.WriteTabAsSpecial, true);
        out.writeString("\t\n \b\n\r\f\\ \"");
        Assert.assertEquals("\"\\t\\n \\b\\n\\r\\f\\\\ \\\"\"", out.toString());
    }
View Full Code Here


                return name;
            }

        };

        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Bean a = new Bean();
        serializer.write(a);

        String text = out.toString();
        Assert.assertEquals("{\"ID\":0}", text);
    }
View Full Code Here

                return name;
            }

        };

        SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.getNameFilters().add(filter);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", (short) 0);
        serializer.write(map);

        String text = out.toString();
        Assert.assertEquals("{\"ID\":0}", text);
    }
View Full Code Here

import com.alibaba.fastjson.serializer.SerializerFeature;

public class MapSerializerTest extends TestCase {

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

        MapSerializer mapSerializer = new MapSerializer();
        mapSerializer.write(new JSONSerializer(out), Collections.EMPTY_MAP, null, null);

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

        Assert.assertEquals("{}", out.toString());
    }

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

        MapSerializer mapSerializer = new MapSerializer();
        mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A", 1), null, null);

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

        Assert.assertEquals("{\"A\":1}", out.toString());
    }

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

        MapSerializer mapSerializer = new MapSerializer();
        Map<String, Integer> map = new LinkedHashMap<String, Integer>();
        map.put("A", 1);
        map.put("B", 2);
        mapSerializer.write(new JSONSerializer(out), map, null, null);

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

        Assert.assertEquals("{\"A\":1,\"B\":2}", out.toString());
    }

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

        MapSerializer mapSerializer = new MapSerializer();
        Map<String, Long> map = new LinkedHashMap<String, Long>();
        map.put("A", 1L);
        map.put("B", 2L);
        mapSerializer.write(new JSONSerializer(out), map, null, null);

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

        Assert.assertEquals("{\"A\":1,\"B\":2}", out.toString());
    }

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

        MapSerializer mapSerializer = new MapSerializer();
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put("A", "1");
        map.put("B", "2");
        mapSerializer.write(new JSONSerializer(out), map, null, null);

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

        Assert.assertEquals("{\"A\":\"1\",\"B\":\"2\"}", out.toString());
    }

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.config(SerializerFeature.UseSingleQuotes, true);

        MapSerializer mapSerializer = new MapSerializer();
        Map<String, String> map = new LinkedHashMap<String, String>();
        map.put("A", "1");
        map.put("B", "2");
        mapSerializer.write(serializer, map, null, null);

        Assert.assertEquals("{'A':'1','B':'2'}", out.toString());
    }
View Full Code Here

        Assert.assertEquals("{'A':'1','B':'2'}", out.toString());
    }

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

        MapSerializer mapSerializer = new MapSerializer();
        mapSerializer.write(new JSONSerializer(out), Collections.singletonMap("A\nB", 1), null, null);

        Assert.assertEquals("{\"A\\nB\":1}", out.toString());
    }
View Full Code Here

TOP

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

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.