convert优化features
This commit is contained in:
@@ -4,6 +4,7 @@ package org.redkale.test.convert;
|
||||
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertFactory;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ public class Json5Test {
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
JsonFactory factory = JsonFactory.root().tiny(true).nullable(true);
|
||||
JsonFactory factory = JsonFactory.root().features(ConvertFactory.FEATURE_TINY | ConvertFactory.FEATURE_NULLABLE);
|
||||
final JsonConvert convert = factory.getConvert();
|
||||
Json5Bean bean = new Json5Bean();
|
||||
bean.id = 60;
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertFactory;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ public class JsonMainTest {
|
||||
|
||||
@Test
|
||||
public void run1() throws Throwable {
|
||||
JsonFactory factory = JsonFactory.root().tiny(true);
|
||||
JsonFactory factory = JsonFactory.root().features(ConvertFactory.FEATURE_TINY);
|
||||
final JsonConvert convert = JsonConvert.root();
|
||||
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);
|
||||
@@ -53,7 +54,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, false, () -> ByteBuffer.allocate(1)) {
|
||||
JsonByteBufferWriter writer = new JsonByteBufferWriter(0, () -> ByteBuffer.allocate(1)) {
|
||||
};
|
||||
convert.convertTo(writer, SimpleEntity.class, entry);
|
||||
ByteBuffer[] buffers = writer.toBuffers();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
package org.redkale.test.convert;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.ConvertFactory;
|
||||
import org.redkale.convert.json.*;
|
||||
|
||||
/**
|
||||
@@ -24,17 +25,21 @@ public class TinyTest {
|
||||
TinyRecord record = new TinyRecord();
|
||||
record.id = 5;
|
||||
{
|
||||
JsonFactory factory = JsonFactory.create().tiny(true);
|
||||
JsonFactory factory = JsonFactory.create().features(ConvertFactory.FEATURE_TINY);
|
||||
JsonConvert convert = factory.getConvert();
|
||||
String json = "{\"id\":5}";
|
||||
if (!main) Assertions.assertEquals(json, convert.convertTo(record));
|
||||
if (!main) {
|
||||
Assertions.assertEquals(json, convert.convertTo(record));
|
||||
}
|
||||
System.out.println(convert.convertTo(record));
|
||||
}
|
||||
{
|
||||
JsonFactory factory = JsonFactory.create().tiny(false);
|
||||
JsonFactory factory = JsonFactory.create().features(0);
|
||||
JsonConvert convert = factory.getConvert();
|
||||
String json = "{\"id\":5,\"name\":\"\"}";
|
||||
if (!main) Assertions.assertEquals(json, convert.convertTo(record));
|
||||
if (!main) {
|
||||
Assertions.assertEquals(json, convert.convertTo(record));
|
||||
}
|
||||
System.out.println(convert.convertTo(record));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user