优化ConvertFactory.features
This commit is contained in:
@@ -762,6 +762,6 @@ public final class ApiDocCommand {
|
|||||||
return example;
|
return example;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final JsonFactory exampleFactory = JsonFactory.create().features(0);
|
private static final JsonFactory exampleFactory = JsonFactory.create().withFeatures(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,10 +22,17 @@ import org.redkale.util.*;
|
|||||||
*/
|
*/
|
||||||
public abstract class Convert<R extends Reader, W extends Writer> {
|
public abstract class Convert<R extends Reader, W extends Writer> {
|
||||||
|
|
||||||
protected final ConvertFactory<R, W> factory;
|
//值为true时 String类型值为"",Boolean类型值为false时不会输出,默认为false
|
||||||
|
public static final int FEATURE_TINY = 1 << 1;
|
||||||
|
|
||||||
|
//值为true时 字段值为null时会输出,默认为false
|
||||||
|
public static final int FEATURE_NULLABLE = 1 << 2;
|
||||||
|
|
||||||
|
//配置属性集合, 1<<1至1<<10为系统内置
|
||||||
protected final int features;
|
protected final int features;
|
||||||
|
|
||||||
|
protected final ConvertFactory<R, W> factory;
|
||||||
|
|
||||||
protected Convert(ConvertFactory<R, W> factory, int features) {
|
protected Convert(ConvertFactory<R, W> factory, int features) {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.features = features;
|
this.features = features;
|
||||||
@@ -39,7 +46,8 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
|||||||
return writer;
|
return writer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc, BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
protected <S extends W> S fieldFunc(S writer, BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||||
|
BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc) {
|
||||||
writer.mapFieldFunc = mapFieldFunc;
|
writer.mapFieldFunc = mapFieldFunc;
|
||||||
writer.objFieldFunc = objFieldFunc;
|
writer.objFieldFunc = objFieldFunc;
|
||||||
writer.objExtFunc = objExtFunc;
|
writer.objExtFunc = objExtFunc;
|
||||||
@@ -58,7 +66,8 @@ public abstract class Convert<R extends Reader, W extends Writer> {
|
|||||||
return newConvert(objFieldFunc, null, objExtFunc);
|
return newConvert(objFieldFunc, null, objExtFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Convert<R, W> newConvert(BiFunction<Attribute, Object, Object> objFieldFunc, BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc);
|
public abstract Convert<R, W> newConvert(BiFunction<Attribute, Object, Object> objFieldFunc,
|
||||||
|
BiFunction<Object, Object, Object> mapFieldFunc, Function<Object, ConvertField[]> objExtFunc);
|
||||||
|
|
||||||
public abstract boolean isBinary();
|
public abstract boolean isBinary();
|
||||||
|
|
||||||
|
|||||||
@@ -36,12 +36,6 @@ import org.redkale.util.*;
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||||
|
|
||||||
//值为true时 String类型值为"",Boolean类型值为false时不会输出,默认为false
|
|
||||||
public static final int FEATURE_TINY = 1 << 1;
|
|
||||||
|
|
||||||
//值为true时 字段值为null时会输出,默认为false
|
|
||||||
public static final int FEATURE_NULLABLE = 1 << 2;
|
|
||||||
|
|
||||||
private static final AtomicBoolean loaderInited = new AtomicBoolean();
|
private static final AtomicBoolean loaderInited = new AtomicBoolean();
|
||||||
|
|
||||||
private static Convert defProtobufConvert;
|
private static Convert defProtobufConvert;
|
||||||
@@ -50,7 +44,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
|||||||
|
|
||||||
protected Convert<R, W> convert;
|
protected Convert<R, W> convert;
|
||||||
|
|
||||||
//配置属性集合, 1<<1至1<<10为系统内置
|
//配置属性集合
|
||||||
protected int features;
|
protected int features;
|
||||||
|
|
||||||
private final Encodeable<W, ?> anyEncoder = new AnyEncoder(this);
|
private final Encodeable<W, ?> anyEncoder = new AnyEncoder(this);
|
||||||
@@ -213,17 +207,6 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int features() {
|
|
||||||
return this.features;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConvertFactory features(int features) {
|
|
||||||
if (features > -1) {
|
|
||||||
this.features = features;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConvertFactory parent() {
|
public ConvertFactory parent() {
|
||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
@@ -348,30 +331,51 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
|||||||
return convert;
|
return convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean tinyFeature(int features) {
|
public final int getFeatures() {
|
||||||
return (features & FEATURE_TINY) > 0;
|
return this.features;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean nullableFeature(int features) {
|
protected <F extends ConvertFactory<R, W>> F withFeatures(int features) {
|
||||||
return (features & FEATURE_NULLABLE) > 0;
|
if (features > -1) {
|
||||||
}
|
this.features = features;
|
||||||
|
|
||||||
public ConvertFactory tiny(boolean tiny) {
|
|
||||||
if (tiny) {
|
|
||||||
this.features |= FEATURE_TINY;
|
|
||||||
} else {
|
|
||||||
this.features = this.features & ~FEATURE_TINY;
|
|
||||||
}
|
}
|
||||||
return this;
|
return (F) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConvertFactory nullable(boolean nullable) {
|
protected <F extends ConvertFactory<R, W>> F addFeature(int feature) {
|
||||||
if (nullable) {
|
if (feature > 0) {
|
||||||
this.features |= FEATURE_NULLABLE;
|
if (features > -1) {
|
||||||
} else {
|
this.features |= feature;
|
||||||
this.features = this.features & ~FEATURE_NULLABLE;
|
} else {
|
||||||
|
this.features = feature;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return (F) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <F extends ConvertFactory<R, W>> F removeFeature(int feature) {
|
||||||
|
if (feature > 0) {
|
||||||
|
if (features > -1) {
|
||||||
|
this.features = this.features & ~feature;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (F) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <F extends ConvertFactory<R, W>> F withTinyFeature(boolean tiny) {
|
||||||
|
return tiny ? addFeature(Convert.FEATURE_TINY) : removeFeature(Convert.FEATURE_NULLABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <F extends ConvertFactory<R, W>> F withNullableFeature(boolean nullable) {
|
||||||
|
return nullable ? addFeature(Convert.FEATURE_NULLABLE) : removeFeature(Convert.FEATURE_NULLABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkTinyFeature(int features) {
|
||||||
|
return (features & Convert.FEATURE_TINY) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkNullableFeature(int features) {
|
||||||
|
return (features & Convert.FEATURE_NULLABLE) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConvertDisabled(AccessibleObject element) {
|
public boolean isConvertDisabled(AccessibleObject element) {
|
||||||
|
|||||||
@@ -80,18 +80,16 @@ public abstract class Writer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Writer features(int features) {
|
public Writer features(int features) {
|
||||||
if (features > -1) {
|
this.features = features;
|
||||||
this.features = features;
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean tiny() {
|
protected final boolean tiny() {
|
||||||
return ConvertFactory.tinyFeature(features);
|
return ConvertFactory.checkTinyFeature(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean nullable() {
|
protected final boolean nullable() {
|
||||||
return ConvertFactory.nullableFeature(features);
|
return ConvertFactory.checkNullableFeature(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import org.redkale.util.TypeToken;
|
|||||||
public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||||
|
|
||||||
private static final BsonFactory instance = new BsonFactory(null,
|
private static final BsonFactory instance = new BsonFactory(null,
|
||||||
getSystemPropertyInt("redkale.convert.bson.tiny", "redkale.convert.tiny", true, FEATURE_TINY)
|
getSystemPropertyInt("redkale.convert.bson.tiny", "redkale.convert.tiny", true, Convert.FEATURE_TINY)
|
||||||
| getSystemPropertyInt("redkale.convert.bson.nullable", "redkale.convert.nullable", false, FEATURE_NULLABLE)
|
| getSystemPropertyInt("redkale.convert.bson.nullable", "redkale.convert.nullable", false, Convert.FEATURE_NULLABLE)
|
||||||
);
|
);
|
||||||
|
|
||||||
static final Decodeable objectDecoder = instance.loadDecoder(Object.class);
|
static final Decodeable objectDecoder = instance.loadDecoder(Object.class);
|
||||||
@@ -56,23 +56,28 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BsonFactory tiny(boolean tiny) {
|
public BsonFactory withFeatures(int features) {
|
||||||
super.tiny(tiny);
|
return super.withFeatures(features);
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean tiny() {
|
|
||||||
return (this.features & FEATURE_TINY) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BsonFactory nullable(boolean nullable) {
|
public BsonFactory addFeature(int feature) {
|
||||||
super.nullable(nullable);
|
return super.addFeature(feature);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean nullable() {
|
@Override
|
||||||
return (this.features & FEATURE_NULLABLE) > 0;
|
public BsonFactory removeFeature(int feature) {
|
||||||
|
return super.removeFeature(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BsonFactory withTinyFeature(boolean tiny) {
|
||||||
|
return super.withTinyFeature(tiny);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BsonFactory withNullableFeature(boolean nullable) {
|
||||||
|
return super.withNullableFeature(nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class BsonWriter extends Writer implements ByteTuple {
|
|||||||
|
|
||||||
public BsonWriter() {
|
public BsonWriter() {
|
||||||
this(defaultSize);
|
this(defaultSize);
|
||||||
this.features = BsonFactory.root().features();
|
this.features = BsonFactory.root().getFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BsonWriter(int size) {
|
public BsonWriter(int size) {
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ public abstract class JsonDynEncoder<T> implements Encodeable<JsonWriter, T> {
|
|||||||
final Map<String, AccessibleObject> mixedNames = mixedNames0;
|
final Map<String, AccessibleObject> mixedNames = mixedNames0;
|
||||||
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
||||||
final String newDynName = "org/redkaledyn/json/_Dyn" + JsonDynEncoder.class.getSimpleName()
|
final String newDynName = "org/redkaledyn/json/_Dyn" + JsonDynEncoder.class.getSimpleName()
|
||||||
+ "__" + clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.features() + "_" + Utility.md5Hex(memberb.toString()); //tiny必须要加上, 同一个类会有多个字段定制Convert
|
+ "__" + clazz.getName().replace('.', '_').replace('$', '_') + "_" + factory.getFeatures() + "_" + Utility.md5Hex(memberb.toString()); //tiny必须要加上, 同一个类会有多个字段定制Convert
|
||||||
try {
|
try {
|
||||||
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
Class clz = RedkaleClassLoader.findDynClass(newDynName.replace('/', '.'));
|
||||||
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
Class newClazz = clz == null ? loader.loadClass(newDynName.replace('/', '.')) : clz;
|
||||||
@@ -511,8 +511,8 @@ public abstract class JsonDynEncoder<T> implements Encodeable<JsonWriter, T> {
|
|||||||
|
|
||||||
int maxLocals = 4;
|
int maxLocals = 4;
|
||||||
int elementIndex = -1;
|
int elementIndex = -1;
|
||||||
final boolean tiny = ConvertFactory.tinyFeature(factory.features());
|
final boolean tiny = ConvertFactory.checkTinyFeature(factory.getFeatures());
|
||||||
final boolean nullable = ConvertFactory.nullableFeature(factory.features());
|
final boolean nullable = ConvertFactory.checkNullableFeature(factory.getFeatures());
|
||||||
final Class firstType = readGetSetFieldType(members.get(0));
|
final Class firstType = readGetSetFieldType(members.get(0));
|
||||||
final boolean mustHadComma = firstType.isPrimitive() && (firstType != boolean.class || !tiny || nullable); //byte/short/char/int/float/long/double
|
final boolean mustHadComma = firstType.isPrimitive() && (firstType != boolean.class || !tiny || nullable); //byte/short/char/int/float/long/double
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import org.redkale.util.Uint128;
|
|||||||
public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||||
|
|
||||||
private static final JsonFactory instance = new JsonFactory(null,
|
private static final JsonFactory instance = new JsonFactory(null,
|
||||||
getSystemPropertyInt("redkale.convert.json.tiny", "redkale.convert.tiny", false, FEATURE_TINY)
|
getSystemPropertyInt("redkale.convert.json.tiny", "redkale.convert.tiny", false, Convert.FEATURE_TINY)
|
||||||
| getSystemPropertyInt("redkale.convert.json.nullable", "redkale.convert.nullable", false, FEATURE_NULLABLE)
|
| getSystemPropertyInt("redkale.convert.json.nullable", "redkale.convert.nullable", false, Convert.FEATURE_NULLABLE)
|
||||||
);
|
);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -56,9 +56,24 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonFactory features(int features) {
|
public JsonFactory withFeatures(int features) {
|
||||||
this.features = features;
|
return super.withFeatures(features);
|
||||||
return this;
|
}
|
||||||
|
|
||||||
|
public JsonFactory addFeature(int feature) {
|
||||||
|
return super.addFeature(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonFactory removeFeature(int feature) {
|
||||||
|
return super.removeFeature(feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonFactory withTinyFeature(boolean tiny) {
|
||||||
|
return super.withTinyFeature(tiny);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonFactory withNullableFeature(boolean nullable) {
|
||||||
|
return super.withNullableFeature(nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -72,8 +87,8 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonFactory create() {
|
public static JsonFactory create() {
|
||||||
return new JsonFactory(null, instance.features());
|
return new JsonFactory(null, instance.getFeatures());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <E> Encodeable<JsonWriter, E> createDyncEncoder(Type type) {
|
protected <E> Encodeable<JsonWriter, E> createDyncEncoder(Type type) {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public abstract class JsonWriter extends Writer {
|
|||||||
protected static final int defaultSize = Integer.getInteger("redkale.convert.json.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024));
|
protected static final int defaultSize = Integer.getInteger("redkale.convert.json.writer.buffer.defsize", Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024));
|
||||||
|
|
||||||
protected JsonWriter() {
|
protected JsonWriter() {
|
||||||
this.features = JsonFactory.root().features();
|
this.features = JsonFactory.root().getFeatures();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonWriter features(int features) {
|
public JsonWriter features(int features) {
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
final JsonFactory childFactory = JsonFactory.create();
|
final JsonFactory childFactory = JsonFactory.create();
|
||||||
if (features > -1) {
|
if (features > -1) {
|
||||||
childFactory.features(features);
|
childFactory.withFeatures(features);
|
||||||
}
|
}
|
||||||
List<Class> types = new ArrayList<>();
|
List<Class> types = new ArrayList<>();
|
||||||
Set<Class> reloadTypes = new HashSet<>();
|
Set<Class> reloadTypes = new HashSet<>();
|
||||||
@@ -212,7 +212,7 @@ public final class Rest {
|
|||||||
}
|
}
|
||||||
types.add(rc.type());
|
types.add(rc.type());
|
||||||
if (rc.features() > -1) {
|
if (rc.features() > -1) {
|
||||||
childFactory.features(rc.features());
|
childFactory.withFeatures(rc.features());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.test.convert;
|
package org.redkale.test.convert;
|
||||||
|
|
||||||
import org.redkale.util.TypeToken;
|
import java.lang.reflect.Type;
|
||||||
import org.redkale.convert.json.JsonFactory;
|
|
||||||
import java.lang.reflect.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
|
import org.redkale.util.TypeToken;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持泛型的
|
* 支持泛型的
|
||||||
@@ -36,7 +35,7 @@ public class GenericEntity<T, K, V> {
|
|||||||
bean.setEntry(new Entry<>("aaaa", SimpleEntity.create()));
|
bean.setEntry(new Entry<>("aaaa", SimpleEntity.create()));
|
||||||
final Type type = new TypeToken<GenericEntity<Long, String, SimpleEntity>>() {
|
final Type type = new TypeToken<GenericEntity<Long, String, SimpleEntity>>() {
|
||||||
}.getType();
|
}.getType();
|
||||||
JsonFactory.root().tiny(true);
|
JsonFactory.root().withTinyFeature(true);
|
||||||
String json = JsonConvert.root().convertTo(bean);
|
String json = JsonConvert.root().convertTo(bean);
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
System.out.println(JsonConvert.root().convertFrom(type, json).toString());
|
System.out.println(JsonConvert.root().convertFrom(type, json).toString());
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ package org.redkale.test.convert;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.redkale.convert.ConvertFactory;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +24,7 @@ public class Json5Test {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run1() throws Exception {
|
public void run1() throws Exception {
|
||||||
JsonFactory factory = JsonFactory.root().features(ConvertFactory.FEATURE_TINY | ConvertFactory.FEATURE_NULLABLE);
|
JsonFactory factory = JsonFactory.root().withFeatures(Convert.FEATURE_TINY | Convert.FEATURE_NULLABLE);
|
||||||
final JsonConvert convert = factory.getConvert();
|
final JsonConvert convert = factory.getConvert();
|
||||||
Json5Bean bean = new Json5Bean();
|
Json5Bean bean = new Json5Bean();
|
||||||
bean.id = 60;
|
bean.id = 60;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.io.*;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.redkale.convert.ConvertFactory;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,7 +33,7 @@ public class JsonMainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run1() throws Throwable {
|
public void run1() throws Throwable {
|
||||||
JsonFactory factory = JsonFactory.root().features(ConvertFactory.FEATURE_TINY);
|
JsonFactory factory = JsonFactory.root().withFeatures(Convert.FEATURE_TINY);
|
||||||
final JsonConvert convert = JsonConvert.root();
|
final JsonConvert convert = JsonConvert.root();
|
||||||
String json = "{\"access_token\":\"null\",\"priv\":null, vvv:nulla,\"priv2\":\"nulla\",\"expires_in\":7200, \"aa\":\"\"}";
|
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);
|
Map<String, String> map = convert.convertFrom(JsonConvert.TYPE_MAP_STRING_STRING, json);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
package org.redkale.test.convert;
|
package org.redkale.test.convert;
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.redkale.convert.ConvertFactory;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +25,7 @@ public class TinyTest {
|
|||||||
TinyRecord record = new TinyRecord();
|
TinyRecord record = new TinyRecord();
|
||||||
record.id = 5;
|
record.id = 5;
|
||||||
{
|
{
|
||||||
JsonFactory factory = JsonFactory.create().features(ConvertFactory.FEATURE_TINY);
|
JsonFactory factory = JsonFactory.create().withFeatures(Convert.FEATURE_TINY);
|
||||||
JsonConvert convert = factory.getConvert();
|
JsonConvert convert = factory.getConvert();
|
||||||
String json = "{\"id\":5}";
|
String json = "{\"id\":5}";
|
||||||
if (!main) {
|
if (!main) {
|
||||||
@@ -34,7 +34,7 @@ public class TinyTest {
|
|||||||
System.out.println(convert.convertTo(record));
|
System.out.println(convert.convertTo(record));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
JsonFactory factory = JsonFactory.create().features(0);
|
JsonFactory factory = JsonFactory.create().withFeatures(0);
|
||||||
JsonConvert convert = factory.getConvert();
|
JsonConvert convert = factory.getConvert();
|
||||||
String json = "{\"id\":5,\"name\":\"\"}";
|
String json = "{\"id\":5,\"name\":\"\"}";
|
||||||
if (!main) {
|
if (!main) {
|
||||||
|
|||||||
Reference in New Issue
Block a user