ConvertFactory增加nullable配置

This commit is contained in:
redkale
2023-07-29 09:20:13 +08:00
parent e20d398a73
commit b84006d8db
24 changed files with 436 additions and 130 deletions

View File

@@ -20,6 +20,19 @@ import org.redkale.util.*;
*/
public class BsonMainTest {
public static void main(String[] args) throws Throwable {
BsonMainTest test = new BsonMainTest();
test.run1();
test.run2();
test.run3();
test.run4();
test.run5();
test.run6();
test.run7();
test.run8();
}
@Test
public void run1() throws Throwable {
Serializable[] sers = new Serializable[]{"aaa", 4};
@@ -38,7 +51,7 @@ public class BsonMainTest {
SimpleChildEntity entry = SimpleChildEntity.create();
byte[] bytes = convert.convertTo(SimpleEntity.class, entry);
System.out.println("长度: " + bytes.length);
Assertions.assertEquals(271, bytes.length);
Assertions.assertEquals(260, bytes.length);
BsonByteBufferWriter writer = convert.pollWriter(() -> ByteBuffer.allocate(1));
convert.convertTo(writer, SimpleEntity.class, entry);
ByteBuffer[] buffers = writer.toBuffers();
@@ -52,7 +65,7 @@ public class BsonMainTest {
b.flip();
}
System.out.println("长度: " + len);
Assertions.assertEquals(271, len);
Assertions.assertEquals(260, len);
SimpleChildEntity entry2 = convert.convertFrom(SimpleChildEntity.class, buffers);
System.out.println(entry);
Assertions.assertEquals(entry.toString(), entry2.toString());

View File

@@ -17,11 +17,21 @@ public class Json5Test {
public static void main(String[] args) throws Throwable {
Json5Test test = new Json5Test();
test.main = true;
test.run();
test.run1();
test.run2();
}
@Test
public void run() throws Exception {
public void run1() throws Exception {
JsonFactory factory = JsonFactory.root().tiny(true).nullable(true);
final JsonConvert convert = factory.getConvert();
Json5Bean bean = new Json5Bean();
bean.id = 60;
System.out.println(convert.convertTo(bean));
}
@Test
public void run2() throws Exception {
JsonConvert convert = JsonConvert.root();
Json5Bean bean = new Json5Bean();
bean.id = 500;

View File

@@ -37,6 +37,7 @@ public class JsonMainTest {
String json = "{\"access_token\":\"null\",\"priv\":null, vvv:nulla,\"priv2\":\"nulla\",\"expires_in\":7200, \"aa\":\"\"}";
Map<String, String> map = convert.convertFrom(JsonConvert.TYPE_MAP_STRING_STRING, json);
System.out.println(map);
System.out.println(map.get("priv") == null);
String rs = convert.convertTo(map);
System.out.println(rs);
ByteBuffer[] buffers = convert.convertTo(() -> ByteBuffer.allocate(1024), map);
@@ -52,7 +53,7 @@ public class JsonMainTest {
SimpleChildEntity entry = SimpleChildEntity.create();
String json = convert.convertTo(SimpleEntity.class, entry);
System.out.println("长度: " + json.length());
JsonByteBufferWriter writer = new JsonByteBufferWriter(false, () -> ByteBuffer.allocate(1)) {
JsonByteBufferWriter writer = new JsonByteBufferWriter(false, false, () -> ByteBuffer.allocate(1)) {
};
convert.convertTo(writer, SimpleEntity.class, entry);
ByteBuffer[] buffers = writer.toBuffers();