Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.JSONSerializer


        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


        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

    }

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

    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

    public void test_special2_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

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

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

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

        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put("TOP", "value");
        map.put("bytes", new byte[] { 1, 2 });

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

        String text = out.toString();
        Assert.assertEquals("{\"TOP\":\"value\",\"bytes\":\"AQI=\"}", text);
       
        JSONObject json = JSON.parseObject(text);
View Full Code Here

import com.alibaba.fastjson.serializer.SerializerFeature;


public class ColorTest2 extends TestCase {
    public void test_color() throws Exception {
        JSONSerializer serializer = new JSONSerializer();
        Assert.assertEquals(ColorSerializer.class, serializer.getObjectWriter(Color.class).getClass());
       
        Color color = Color.RED;
        String text = JSON.toJSONString(color, SerializerFeature.WriteClassName);
        System.out.println(text);
       
View Full Code Here

public class IntegerArrayEncodeTest extends TestCase {

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(new Integer[] { 0, 1 });

        Assert.assertEquals("[0,1]", out.toString());
    }
View Full Code Here

    }

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

        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(new Integer[] {});

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

TOP

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

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.