This commit is contained in:
@@ -5,12 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.test.convert;
|
package org.redkale.test.convert;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import org.redkale.convert.bson.BsonByteBufferWriter;
|
import org.redkale.convert.bson.BsonByteBufferWriter;
|
||||||
import org.redkale.convert.bson.BsonFactory;
|
import org.redkale.convert.bson.BsonFactory;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
import org.redkale.convert.bson.BsonConvert;
|
import org.redkale.convert.bson.BsonConvert;
|
||||||
import org.redkale.convert.json.JsonFactory;
|
import org.redkale.convert.json.JsonFactory;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -27,9 +27,34 @@ public class BsonTestMain {
|
|||||||
Serializable[] a = convert.convertFrom(Serializable[].class, bytes);
|
Serializable[] a = convert.convertFrom(Serializable[].class, bytes);
|
||||||
System.out.println(Arrays.toString(a));
|
System.out.println(Arrays.toString(a));
|
||||||
main2(args);
|
main2(args);
|
||||||
|
main3(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main2(String[] args) throws Exception {
|
public static void main2(String[] args) throws Exception {
|
||||||
|
System.out.println(new String(new byte[]{109, 121, 110, 97, 109, 101}));
|
||||||
|
final BsonConvert convert = BsonFactory.root().getConvert();
|
||||||
|
SimpleChildEntity entry = SimpleChildEntity.create();
|
||||||
|
byte[] bytes = convert.convertTo(SimpleEntity.class, entry);
|
||||||
|
System.out.println("长度: " + bytes.length);
|
||||||
|
BsonByteBufferWriter writer = convert.pollBsonWriter(() -> 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);
|
||||||
|
SimpleChildEntity entry2 = convert.convertFrom(SimpleChildEntity.class, buffers);
|
||||||
|
System.out.println(entry);
|
||||||
|
System.out.println(entry2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main3(String[] args) throws Exception {
|
||||||
final BsonConvert convert = BsonFactory.root().getConvert();
|
final BsonConvert convert = BsonFactory.root().getConvert();
|
||||||
SimpleChildEntity entry = SimpleChildEntity.create();
|
SimpleChildEntity entry = SimpleChildEntity.create();
|
||||||
byte[] bytes = convert.convertTo(SimpleEntity.class, entry);
|
byte[] bytes = convert.convertTo(SimpleEntity.class, entry);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import java.util.*;
|
|||||||
@ConvertEntity("myname")
|
@ConvertEntity("myname")
|
||||||
public class SimpleChildEntity extends SimpleEntity {
|
public class SimpleChildEntity extends SimpleEntity {
|
||||||
|
|
||||||
|
private short st = -1234;
|
||||||
|
|
||||||
private String extend;
|
private String extend;
|
||||||
|
|
||||||
public static SimpleChildEntity create() {
|
public static SimpleChildEntity create() {
|
||||||
@@ -37,6 +39,14 @@ public class SimpleChildEntity extends SimpleEntity {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getSt() {
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSt(short st) {
|
||||||
|
this.st = st;
|
||||||
|
}
|
||||||
|
|
||||||
public String getExtend() {
|
public String getExtend() {
|
||||||
return extend;
|
return extend;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ import java.io.*;
|
|||||||
import static java.lang.Thread.sleep;
|
import static java.lang.Thread.sleep;
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
import static java.lang.Thread.sleep;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user