Package com.alibaba.fastjson.serializer

Examples of com.alibaba.fastjson.serializer.SerializeWriter.writeTo()


        ByteArrayOutputStream os = new ByteArrayOutputStream();
        SerializeWriter out = new SerializeWriter(SerializerFeature.WriteClassName);
        // SerializeWriter out = new SerializeWriter();
        JSONSerializer serializer = new JSONSerializer(out);
        serializer.write(t);
        out.writeTo(os, "UTF-8");
        os.toByteArray();
        //System.out.println(JSON.toJSONString(t, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat));
        //System.out.println("json " + os.toByteArray().length);
    }
View Full Code Here


    public void test_1 () throws Exception {
        SerializeWriter out = new SerializeWriter(SerializerFeature.UseSingleQuotes);
        out.writeString("abc中文");
       
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        out.writeTo(byteOut, "UTF-8");
        Assert.assertEquals("'abc中文'", new String(byteOut.toByteArray(), "UTF-8"));
    }
   
    public void test_2 () throws Exception {
        SerializeWriter out = new SerializeWriter(SerializerFeature.UseSingleQuotes);
View Full Code Here

        out.write('b');
        out.write('c');
        Assert.assertEquals("abc", out.toString());

        StringWriter writer = new StringWriter();
        out.writeTo(writer);
        Assert.assertEquals("abc", writer.toString());
    }

    public void test_1() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
View Full Code Here

        out.write((int) 'c');
        out.write(new char[0], 0, 0);
        Assert.assertEquals("abc", out.toString());

        StringWriter writer = new StringWriter();
        out.writeTo(writer);
        Assert.assertEquals("abc", writer.toString());

        out.expandCapacity(128);
    }
View Full Code Here

    public void test_1 () throws Exception {
        SerializeWriter out = new SerializeWriter(SerializerFeature.UseSingleQuotes);
        out.writeString("abc中文");
       
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        out.writeTo(byteOut, "UTF-8");
        Assert.assertEquals("'abc中文'", new String(byteOut.toByteArray(), "UTF-8"));
    }
   
    public void test_2 () throws Exception {
        SerializeWriter out = new SerializeWriter(SerializerFeature.UseSingleQuotes);
View Full Code Here

    public void test_error() throws Exception {
        SerializeWriter writer = new SerializeWriter(new StringWriter());
        Exception error = null;
        try {
            writer.writeTo(new StringWriter());
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        writer.close();
View Full Code Here

    public void test_error_2() throws Exception {
        SerializeWriter writer = new SerializeWriter(new StringWriter());
        Exception error = null;
        try {
            writer.writeTo(new ByteArrayOutputStream(), Charset.forName("UTF-8"));
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        writer.close();
View Full Code Here

   
    public void test_error_3() throws Exception {
        SerializeWriter writer = new SerializeWriter(new StringWriter());
        Exception error = null;
        try {
            writer.writeTo(new ByteArrayOutputStream(), "UTF-8");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
        writer.close();
View Full Code Here

        out.write('b');
        out.write('c');
        Assert.assertEquals("abc", out.toString());

        StringWriter writer = new StringWriter();
        out.writeTo(writer);
        Assert.assertEquals("abc", writer.toString());
    }

    public void test_1() throws Exception {
        SerializeWriter out = new SerializeWriter(1);
View Full Code Here

        out.write((int) 'c');
        out.write(new char[0], 0, 0);
        Assert.assertEquals("abc", out.toString());

        StringWriter writer = new StringWriter();
        out.writeTo(writer);
        Assert.assertEquals("abc", writer.toString());

        out.expandCapacity(128);
    }
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.