This commit is contained in:
wentch
2015-12-30 16:51:31 +08:00
parent 959c4c9d88
commit 7546b3de11

View File

@@ -5,10 +5,12 @@
*/
package org.redkale.test.convert;
import java.io.*;
import org.redkale.convert.json.JsonConvert;
import org.redkale.convert.json.JsonFactory;
import java.nio.*;
import java.util.*;
import org.redkale.convert.json.*;
/**
*
@@ -28,5 +30,31 @@ public class JsonTestMain {
byte[] bs = new byte[buffers[0].remaining()];
buffers[0].get(bs);
System.out.println(new String(bs));
main2(args);
}
public static void main2(String[] args) throws Exception {
final JsonConvert convert = JsonFactory.root().getConvert();
SimpleChildEntity entry = SimpleChildEntity.create();
String json = convert.convertTo(SimpleEntity.class, entry);
System.out.println("长度: " + json.length());
JsonByteBufferWriter writer = convert.pollJsonWriter(() -> ByteBuffer.allocate(1));
convert.convertTo(writer,SimpleEntity.class, entry);
ByteBuffer[] buffers = writer.toBuffers();
int len = 0;
ByteArrayOutputStream out = new ByteArrayOutputStream();
for(ByteBuffer b : buffers){
len += b.remaining();
byte[] ts = new byte[b.remaining()];
b.get(ts);
out.write(ts);
b.flip();
}
System.out.println("长度: " + len);
System.out.println(json);
SimpleChildEntity entry2 = convert.convertFrom(SimpleChildEntity.class, buffers);
System.out.println(entry);
System.out.println(entry2);
}
}