本文整理汇总了Java中com.alibaba.fastjson.serializer.SerializeWriter.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java SerializeWriter.writeTo方法的具体用法?Java SerializeWriter.writeTo怎么用?Java SerializeWriter.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.SerializeWriter
的用法示例。
在下文中一共展示了SerializeWriter.writeTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsonSerialize
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
private <T> void jsonSerialize(T t) throws IOException {
// String text = JSON.toJSONString(t, SerializerFeature.WriteClassName, SerializerFeature.PrettyFormat);
// System.out.println(text);
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);
}
示例2: test_erro_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_erro_0() throws Exception {
SerializeWriter out = new SerializeWriter();
out.write(true);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
out.writeTo(byteOut, "UTF-8");
Assert.assertEquals("true", new String(byteOut.toByteArray()));
out.close();
}
示例3: test_0
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_0() throws Exception {
SerializeWriter out = new SerializeWriter(1);
out.write('a');
out.write('b');
out.write('c');
Assert.assertEquals("abc", out.toString());
StringWriter writer = new StringWriter();
out.writeTo(writer);
Assert.assertEquals("abc", writer.toString());
}
示例4: test_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void test_1() throws Exception {
SerializeWriter out = new SerializeWriter(1);
out.write((int) 'a');
out.write((int) 'b');
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);
}
示例5: test_error
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
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();
}
示例6: test_error_2
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
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();
}
示例7: test_error_3
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
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();
}
示例8: test_1
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
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"));
}
示例9: writeObject
import com.alibaba.fastjson.serializer.SerializeWriter; //导入方法依赖的package包/类
public void writeObject(Object obj) throws IOException {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.WriteEnumUsingToString, true);
serializer.write(obj);
out.writeTo(writer);
writer.println();
writer.flush();
}