anyvalue
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
/**
|
||||
* AnyValue的Decoder实现
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <R> Reader输入的子类型
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public class AnyValueDecoder<R extends Reader> implements Decodeable<R, AnyValue> {
|
||||
|
||||
protected final ConvertFactory factory;
|
||||
|
||||
public AnyValueDecoder(final ConvertFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnyValue convertFrom(R in) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return AnyValue.class;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.convert;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.util.AnyValue;
|
||||
|
||||
/**
|
||||
* AnyValue的Encoder实现
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <W> Writer输出的子类
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public class AnyValueEncoder<W extends Writer> implements Encodeable<W, AnyValue> {
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, AnyValue value) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return AnyValue.class;
|
||||
}
|
||||
}
|
||||
@@ -78,133 +78,150 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|
||||
|
||||
private Consumer<BiFunction> fieldFuncConsumer;
|
||||
|
||||
@SuppressWarnings("OverridableMethodCallInConstructor")
|
||||
protected ConvertFactory(ConvertFactory<R, W> parent, int features) {
|
||||
this.features = features;
|
||||
this.parent = parent;
|
||||
if (parent == null) {
|
||||
// ---------------------------------------------------------
|
||||
this.initPrimitiveCoderInRoot();
|
||||
this.initSimpleCoderInRoot();
|
||||
this.initObjectCoderInRoot();
|
||||
}
|
||||
}
|
||||
|
||||
this.register(boolean.class, BoolSimpledCoder.instance);
|
||||
this.register(Boolean.class, BoolSimpledCoder.instance);
|
||||
protected void initPrimitiveCoderInRoot() {
|
||||
this.register(boolean.class, BoolSimpledCoder.instance);
|
||||
this.register(Boolean.class, BoolSimpledCoder.instance);
|
||||
|
||||
this.register(byte.class, ByteSimpledCoder.instance);
|
||||
this.register(Byte.class, ByteSimpledCoder.instance);
|
||||
this.register(byte.class, ByteSimpledCoder.instance);
|
||||
this.register(Byte.class, ByteSimpledCoder.instance);
|
||||
|
||||
this.register(short.class, ShortSimpledCoder.instance);
|
||||
this.register(Short.class, ShortSimpledCoder.instance);
|
||||
this.register(short.class, ShortSimpledCoder.instance);
|
||||
this.register(Short.class, ShortSimpledCoder.instance);
|
||||
|
||||
this.register(char.class, CharSimpledCoder.instance);
|
||||
this.register(Character.class, CharSimpledCoder.instance);
|
||||
this.register(char.class, CharSimpledCoder.instance);
|
||||
this.register(Character.class, CharSimpledCoder.instance);
|
||||
|
||||
this.register(int.class, IntSimpledCoder.instance);
|
||||
this.register(Integer.class, IntSimpledCoder.instance);
|
||||
this.register(int.class, IntSimpledCoder.instance);
|
||||
this.register(Integer.class, IntSimpledCoder.instance);
|
||||
|
||||
this.register(long.class, LongSimpledCoder.instance);
|
||||
this.register(Long.class, LongSimpledCoder.instance);
|
||||
this.register(long.class, LongSimpledCoder.instance);
|
||||
this.register(Long.class, LongSimpledCoder.instance);
|
||||
|
||||
this.register(float.class, FloatSimpledCoder.instance);
|
||||
this.register(Float.class, FloatSimpledCoder.instance);
|
||||
this.register(float.class, FloatSimpledCoder.instance);
|
||||
this.register(Float.class, FloatSimpledCoder.instance);
|
||||
|
||||
this.register(double.class, DoubleSimpledCoder.instance);
|
||||
this.register(Double.class, DoubleSimpledCoder.instance);
|
||||
this.register(double.class, DoubleSimpledCoder.instance);
|
||||
this.register(Double.class, DoubleSimpledCoder.instance);
|
||||
|
||||
this.register(Number.class, NumberSimpledCoder.instance);
|
||||
this.register(String.class, StringSimpledCoder.instance);
|
||||
this.register(StringWrapper.class, StringWrapperSimpledCoder.instance);
|
||||
this.register(CharSequence.class, CharSequenceSimpledCoder.instance);
|
||||
this.register(StringBuilder.class, CharSequenceSimpledCoder.StringBuilderSimpledCoder.instance);
|
||||
this.register(java.util.Date.class, DateSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, InstantSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, LocalDateSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, LocalTimeSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, LocalDateTimeSimpledCoder.instance);
|
||||
this.register(java.time.Duration.class, DurationSimpledCoder.instance);
|
||||
this.register(AtomicBoolean.class, AtomicBooleanSimpledCoder.instance);
|
||||
this.register(AtomicInteger.class, AtomicIntegerSimpledCoder.instance);
|
||||
this.register(AtomicLong.class, AtomicLongSimpledCoder.instance);
|
||||
this.register(BigInteger.class, BigIntegerSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressSimpledCoder.instance);
|
||||
this.register(LongAdder.class, LongAdderSimpledCoder.instance);
|
||||
this.register(Uint128.class, Uint128SimpledCoder.instance);
|
||||
this.register(Class.class, TypeSimpledCoder.instance);
|
||||
this.register(Pattern.class, PatternSimpledCoder.instance);
|
||||
this.register(File.class, FileSimpledCoder.instance);
|
||||
this.register(Throwable.class, ThrowableSimpledCoder.instance);
|
||||
this.register(CompletionHandler.class, CompletionHandlerSimpledCoder.instance);
|
||||
this.register(URL.class, URLSimpledCoder.instance);
|
||||
this.register(URI.class, URISimpledCoder.instance);
|
||||
// ---------------------------------------------------------
|
||||
this.register(ByteBuffer.class, ByteBufferSimpledCoder.instance);
|
||||
this.register(boolean[].class, BoolArraySimpledCoder.instance);
|
||||
this.register(byte[].class, ByteArraySimpledCoder.instance);
|
||||
this.register(short[].class, ShortArraySimpledCoder.instance);
|
||||
this.register(char[].class, CharArraySimpledCoder.instance);
|
||||
this.register(int[].class, IntArraySimpledCoder.instance);
|
||||
this.register(IntStream.class, IntArraySimpledCoder.IntStreamSimpledCoder.instance);
|
||||
this.register(long[].class, LongArraySimpledCoder.instance);
|
||||
this.register(LongStream.class, LongArraySimpledCoder.LongStreamSimpledCoder.instance);
|
||||
this.register(float[].class, FloatArraySimpledCoder.instance);
|
||||
this.register(double[].class, DoubleArraySimpledCoder.instance);
|
||||
this.register(DoubleStream.class, DoubleArraySimpledCoder.DoubleStreamSimpledCoder.instance);
|
||||
this.register(String[].class, StringArraySimpledCoder.instance);
|
||||
// ---------------------------------------------------------
|
||||
this.register(AnyValue.class, Creator.create(AnyValueWriter.class));
|
||||
this.register(
|
||||
HttpCookie.class, (Object... params) -> new HttpCookie((String) params[0], (String) params[1]));
|
||||
try {
|
||||
Class sqldateClass =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("java.sql.Date");
|
||||
Invoker<Object, Object> sqldateInvoker = Invoker.create(sqldateClass, "valueOf", String.class);
|
||||
this.register(sqldateClass, new SimpledCoder<R, W, Object>() {
|
||||
this.register(Number.class, NumberSimpledCoder.instance);
|
||||
this.register(String.class, StringSimpledCoder.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
protected void initSimpleCoderInRoot() {
|
||||
this.register(StringWrapper.class, StringWrapperSimpledCoder.instance);
|
||||
this.register(CharSequence.class, CharSequenceSimpledCoder.instance);
|
||||
this.register(StringBuilder.class, CharSequenceSimpledCoder.StringBuilderSimpledCoder.instance);
|
||||
this.register(java.util.Date.class, DateSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, InstantSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, LocalDateSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, LocalTimeSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, LocalDateTimeSimpledCoder.instance);
|
||||
this.register(java.time.Duration.class, DurationSimpledCoder.instance);
|
||||
this.register(AtomicBoolean.class, AtomicBooleanSimpledCoder.instance);
|
||||
this.register(AtomicInteger.class, AtomicIntegerSimpledCoder.instance);
|
||||
this.register(AtomicLong.class, AtomicLongSimpledCoder.instance);
|
||||
this.register(BigInteger.class, BigIntegerSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, BigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, InetAddressSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, InetAddressSimpledCoder.InetSocketAddressSimpledCoder.instance);
|
||||
this.register(LongAdder.class, LongAdderSimpledCoder.instance);
|
||||
this.register(Uint128.class, Uint128SimpledCoder.instance);
|
||||
this.register(Class.class, TypeSimpledCoder.instance);
|
||||
this.register(Pattern.class, PatternSimpledCoder.instance);
|
||||
this.register(File.class, FileSimpledCoder.instance);
|
||||
this.register(Throwable.class, ThrowableSimpledCoder.instance);
|
||||
this.register(CompletionHandler.class, CompletionHandlerSimpledCoder.instance);
|
||||
this.register(URL.class, URLSimpledCoder.instance);
|
||||
this.register(URI.class, URISimpledCoder.instance);
|
||||
// ---------------------------------------------------------
|
||||
this.register(ByteBuffer.class, ByteBufferSimpledCoder.instance);
|
||||
this.register(boolean[].class, BoolArraySimpledCoder.instance);
|
||||
this.register(byte[].class, ByteArraySimpledCoder.instance);
|
||||
this.register(short[].class, ShortArraySimpledCoder.instance);
|
||||
this.register(char[].class, CharArraySimpledCoder.instance);
|
||||
this.register(int[].class, IntArraySimpledCoder.instance);
|
||||
this.register(IntStream.class, IntArraySimpledCoder.IntStreamSimpledCoder.instance);
|
||||
this.register(long[].class, LongArraySimpledCoder.instance);
|
||||
this.register(LongStream.class, LongArraySimpledCoder.LongStreamSimpledCoder.instance);
|
||||
this.register(float[].class, FloatArraySimpledCoder.instance);
|
||||
this.register(double[].class, DoubleArraySimpledCoder.instance);
|
||||
this.register(DoubleStream.class, DoubleArraySimpledCoder.DoubleStreamSimpledCoder.instance);
|
||||
this.register(String[].class, StringArraySimpledCoder.instance);
|
||||
// ---------------------------------------------------------
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : sqldateInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
Class sqltimeClass =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("java.sql.Time");
|
||||
Invoker<Object, Object> sqltimeInvoker = Invoker.create(sqltimeClass, "valueOf", String.class);
|
||||
this.register(sqltimeClass, new SimpledCoder<R, W, Object>() {
|
||||
protected void initObjectCoderInRoot() {
|
||||
this.register(AnyValue.class, Creator.create(AnyValueWriter.class));
|
||||
ObjectDecoder anyValueDecoder = createObjectDecoder(AnyValueWriter.class);
|
||||
ObjectEncoder anyValueEncoder = createObjectEncoder(AnyValueWriter.class);
|
||||
this.register(AnyValue.class, anyValueDecoder);
|
||||
this.register(AnyValue.class, anyValueEncoder);
|
||||
this.register(AnyValueWriter.class, anyValueDecoder);
|
||||
this.register(AnyValueWriter.class, anyValueEncoder);
|
||||
anyValueDecoder.init(this);
|
||||
anyValueEncoder.init(this);
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
this.register(HttpCookie.class, (Object... params) -> new HttpCookie((String) params[0], (String) params[1]));
|
||||
try {
|
||||
Class sqldateClass = Thread.currentThread().getContextClassLoader().loadClass("java.sql.Date");
|
||||
Invoker<Object, Object> sqldateInvoker = Invoker.create(sqldateClass, "valueOf", String.class);
|
||||
this.register(sqldateClass, new SimpledCoder<R, W, Object>() {
|
||||
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : sqltimeInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
Class timestampClass =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("java.sql.Timestamp");
|
||||
Invoker<Object, Object> timestampInvoker = Invoker.create(timestampClass, "valueOf", String.class);
|
||||
this.register(timestampClass, new SimpledCoder<R, W, Object>() {
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : sqldateInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
Class sqltimeClass = Thread.currentThread().getContextClassLoader().loadClass("java.sql.Time");
|
||||
Invoker<Object, Object> sqltimeInvoker = Invoker.create(sqltimeClass, "valueOf", String.class);
|
||||
this.register(sqltimeClass, new SimpledCoder<R, W, Object>() {
|
||||
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : timestampInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
// do nothing
|
||||
}
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : sqltimeInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
Class timestampClass =
|
||||
Thread.currentThread().getContextClassLoader().loadClass("java.sql.Timestamp");
|
||||
Invoker<Object, Object> timestampInvoker = Invoker.create(timestampClass, "valueOf", String.class);
|
||||
this.register(timestampClass, new SimpledCoder<R, W, Object>() {
|
||||
|
||||
@Override
|
||||
public void convertTo(W out, Object value) {
|
||||
out.writeStandardString(value == null ? null : value.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convertFrom(R in) {
|
||||
String t = in.readStandardString();
|
||||
return t == null ? null : timestampInvoker.invoke(null, t);
|
||||
}
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,29 +33,29 @@ public final class JsonFactory extends ConvertFactory<JsonReader, JsonWriter> {
|
||||
|
||||
static {
|
||||
instance.register(Serializable.class, instance.loadEncoder(Object.class));
|
||||
|
||||
// instance.register(AnyValue.class, instance.loadDecoder(SimpleAnyValue.class));
|
||||
// instance.register(AnyValue.class, instance.loadEncoder(SimpleAnyValue.class));
|
||||
}
|
||||
|
||||
private JsonFactory(JsonFactory parent, int features) {
|
||||
super(parent, features);
|
||||
if (parent == null) {
|
||||
this.register(InetAddress.class, JsonCoders.InetAddressJsonSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, JsonCoders.InetSocketAddressJsonSimpledCoder.instance);
|
||||
this.register(Uint128.class, JsonCoders.Uint128JsonSimpledCoder.instance);
|
||||
this.register(BigInteger.class, JsonCoders.BigIntegerJsonSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, JsonCoders.BigDecimalJsonSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, JsonCoders.InstantJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, JsonCoders.LocalDateJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, JsonCoders.LocalTimeJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, JsonCoders.LocalDateTimeJsonSimpledCoder.instance);
|
||||
}
|
||||
|
||||
this.register(JsonElement.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonString.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonObject.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonArray.class, (Decodeable) JsonElementDecoder.instance);
|
||||
}
|
||||
@Override
|
||||
protected void initSimpleCoderInRoot() {
|
||||
super.initSimpleCoderInRoot();
|
||||
this.register(InetAddress.class, JsonCoders.InetAddressJsonSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, JsonCoders.InetSocketAddressJsonSimpledCoder.instance);
|
||||
this.register(Uint128.class, JsonCoders.Uint128JsonSimpledCoder.instance);
|
||||
this.register(BigInteger.class, JsonCoders.BigIntegerJsonSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, JsonCoders.BigDecimalJsonSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, JsonCoders.InstantJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, JsonCoders.LocalDateJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, JsonCoders.LocalTimeJsonSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, JsonCoders.LocalDateTimeJsonSimpledCoder.instance);
|
||||
|
||||
this.register(JsonElement.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonString.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonObject.class, (Decodeable) JsonElementDecoder.instance);
|
||||
this.register(JsonArray.class, (Decodeable) JsonElementDecoder.instance);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -372,9 +372,6 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
|
||||
if (!(type instanceof Class)) {
|
||||
return null;
|
||||
}
|
||||
if (AnyValue.class.isAssignableFrom((Class) type)) { // 不支持
|
||||
return null;
|
||||
}
|
||||
return generateDyncEncoder(factory, (Class) type);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,77 +42,82 @@ public class ProtobufFactory extends ConvertFactory<ProtobufReader, ProtobufWrit
|
||||
private ProtobufFactory(ProtobufFactory parent, int features, boolean enumtostring) {
|
||||
super(parent, features);
|
||||
this.enumtostring = enumtostring;
|
||||
if (parent == null) { // root
|
||||
// ---------------------------------------------------------
|
||||
}
|
||||
|
||||
this.register(boolean.class, ProtobufCoders.ProtobufBoolSimpledCoder.instance);
|
||||
this.register(Boolean.class, ProtobufCoders.ProtobufBoolSimpledCoder.instance);
|
||||
@Override
|
||||
protected void initPrimitiveCoderInRoot() {
|
||||
this.register(boolean.class, ProtobufCoders.ProtobufBoolSimpledCoder.instance);
|
||||
this.register(Boolean.class, ProtobufCoders.ProtobufBoolSimpledCoder.instance);
|
||||
|
||||
this.register(byte.class, ProtobufCoders.ProtobufByteSimpledCoder.instance);
|
||||
this.register(Byte.class, ProtobufCoders.ProtobufByteSimpledCoder.instance);
|
||||
this.register(byte.class, ProtobufCoders.ProtobufByteSimpledCoder.instance);
|
||||
this.register(Byte.class, ProtobufCoders.ProtobufByteSimpledCoder.instance);
|
||||
|
||||
this.register(char.class, ProtobufCoders.ProtobufCharSimpledCoder.instance);
|
||||
this.register(Character.class, ProtobufCoders.ProtobufCharSimpledCoder.instance);
|
||||
this.register(char.class, ProtobufCoders.ProtobufCharSimpledCoder.instance);
|
||||
this.register(Character.class, ProtobufCoders.ProtobufCharSimpledCoder.instance);
|
||||
|
||||
this.register(short.class, ProtobufCoders.ProtobufShortSimpledCoder.instance);
|
||||
this.register(Short.class, ProtobufCoders.ProtobufShortSimpledCoder.instance);
|
||||
this.register(short.class, ProtobufCoders.ProtobufShortSimpledCoder.instance);
|
||||
this.register(Short.class, ProtobufCoders.ProtobufShortSimpledCoder.instance);
|
||||
|
||||
this.register(int.class, ProtobufCoders.ProtobufIntSimpledCoder.instance);
|
||||
this.register(Integer.class, ProtobufCoders.ProtobufIntSimpledCoder.instance);
|
||||
this.register(int.class, ProtobufCoders.ProtobufIntSimpledCoder.instance);
|
||||
this.register(Integer.class, ProtobufCoders.ProtobufIntSimpledCoder.instance);
|
||||
|
||||
this.register(float.class, ProtobufCoders.ProtobufFloatSimpledCoder.instance);
|
||||
this.register(Float.class, ProtobufCoders.ProtobufFloatSimpledCoder.instance);
|
||||
this.register(float.class, ProtobufCoders.ProtobufFloatSimpledCoder.instance);
|
||||
this.register(Float.class, ProtobufCoders.ProtobufFloatSimpledCoder.instance);
|
||||
|
||||
this.register(long.class, ProtobufCoders.ProtobufLongSimpledCoder.instance);
|
||||
this.register(Long.class, ProtobufCoders.ProtobufLongSimpledCoder.instance);
|
||||
this.register(long.class, ProtobufCoders.ProtobufLongSimpledCoder.instance);
|
||||
this.register(Long.class, ProtobufCoders.ProtobufLongSimpledCoder.instance);
|
||||
|
||||
this.register(double.class, ProtobufCoders.ProtobufDoubleSimpledCoder.instance);
|
||||
this.register(Double.class, ProtobufCoders.ProtobufDoubleSimpledCoder.instance);
|
||||
this.register(double.class, ProtobufCoders.ProtobufDoubleSimpledCoder.instance);
|
||||
this.register(Double.class, ProtobufCoders.ProtobufDoubleSimpledCoder.instance);
|
||||
|
||||
this.register(Number.class, ProtobufCoders.ProtobufNumberSimpledCoder.instance);
|
||||
this.register(String.class, ProtobufCoders.ProtobufStringSimpledCoder.instance);
|
||||
this.register(StringWrapper.class, ProtobufCoders.ProtobufStringWrapperSimpledCoder.instance);
|
||||
this.register(CharSequence.class, ProtobufCoders.ProtobufCharSequenceSimpledCoder.instance);
|
||||
this.register(StringBuilder.class, ProtobufCoders.ProtobufStringBuilderSimpledCoder.instance);
|
||||
this.register(java.util.Date.class, ProtobufCoders.ProtobufDateSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, ProtobufCoders.ProtobufInstantSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, ProtobufCoders.ProtobufLocalDateSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, ProtobufCoders.ProtobufLocalTimeSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, ProtobufCoders.ProtobufLocalDateTimeSimpledCoder.instance);
|
||||
this.register(java.time.Duration.class, ProtobufCoders.ProtobufDurationSimpledCoder.instance);
|
||||
this.register(AtomicBoolean.class, ProtobufCoders.ProtobufAtomicBooleanSimpledCoder.instance);
|
||||
this.register(AtomicInteger.class, ProtobufCoders.ProtobufAtomicIntegerSimpledCoder.instance);
|
||||
this.register(AtomicLong.class, ProtobufCoders.ProtobufAtomicLongSimpledCoder.instance);
|
||||
this.register(BigInteger.class, ProtobufCoders.ProtobufBigIntegerSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, ProtobufCoders.ProtobufBigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, ProtobufCoders.ProtobufInetAddressSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, ProtobufCoders.ProtobufInetSocketAddressSimpledCoder.instance);
|
||||
this.register(LongAdder.class, ProtobufCoders.ProtobufLongAdderSimpledCoder.instance);
|
||||
this.register(Uint128.class, ProtobufCoders.ProtobufUint128SimpledCoder.instance);
|
||||
this.register(File.class, ProtobufCoders.ProtobufFileSimpledCoder.instance);
|
||||
this.register(Serializable.class, ProtobufCoders.ProtobufSerializableSimpledCoder.instance);
|
||||
this.register(Number.class, ProtobufCoders.ProtobufNumberSimpledCoder.instance);
|
||||
this.register(String.class, ProtobufCoders.ProtobufStringSimpledCoder.instance);
|
||||
}
|
||||
|
||||
this.register(boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder.instance);
|
||||
this.register(byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder.instance);
|
||||
this.register(char[].class, ProtobufCoders.ProtobufCharArraySimpledCoder.instance);
|
||||
this.register(short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder.instance);
|
||||
this.register(int[].class, ProtobufCoders.ProtobufIntArraySimpledCoder.instance);
|
||||
this.register(float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder.instance);
|
||||
this.register(long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder.instance);
|
||||
this.register(double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder.instance);
|
||||
@Override
|
||||
protected void initSimpleCoderInRoot() {
|
||||
super.initSimpleCoderInRoot();
|
||||
this.register(StringWrapper.class, ProtobufCoders.ProtobufStringWrapperSimpledCoder.instance);
|
||||
this.register(CharSequence.class, ProtobufCoders.ProtobufCharSequenceSimpledCoder.instance);
|
||||
this.register(StringBuilder.class, ProtobufCoders.ProtobufStringBuilderSimpledCoder.instance);
|
||||
this.register(java.util.Date.class, ProtobufCoders.ProtobufDateSimpledCoder.instance);
|
||||
this.register(java.time.Instant.class, ProtobufCoders.ProtobufInstantSimpledCoder.instance);
|
||||
this.register(java.time.LocalDate.class, ProtobufCoders.ProtobufLocalDateSimpledCoder.instance);
|
||||
this.register(java.time.LocalTime.class, ProtobufCoders.ProtobufLocalTimeSimpledCoder.instance);
|
||||
this.register(java.time.LocalDateTime.class, ProtobufCoders.ProtobufLocalDateTimeSimpledCoder.instance);
|
||||
this.register(java.time.Duration.class, ProtobufCoders.ProtobufDurationSimpledCoder.instance);
|
||||
this.register(AtomicBoolean.class, ProtobufCoders.ProtobufAtomicBooleanSimpledCoder.instance);
|
||||
this.register(AtomicInteger.class, ProtobufCoders.ProtobufAtomicIntegerSimpledCoder.instance);
|
||||
this.register(AtomicLong.class, ProtobufCoders.ProtobufAtomicLongSimpledCoder.instance);
|
||||
this.register(BigInteger.class, ProtobufCoders.ProtobufBigIntegerSimpledCoder.instance);
|
||||
this.register(BigDecimal.class, ProtobufCoders.ProtobufBigDecimalSimpledCoder.instance);
|
||||
this.register(InetAddress.class, ProtobufCoders.ProtobufInetAddressSimpledCoder.instance);
|
||||
this.register(InetSocketAddress.class, ProtobufCoders.ProtobufInetSocketAddressSimpledCoder.instance);
|
||||
this.register(LongAdder.class, ProtobufCoders.ProtobufLongAdderSimpledCoder.instance);
|
||||
this.register(Uint128.class, ProtobufCoders.ProtobufUint128SimpledCoder.instance);
|
||||
this.register(File.class, ProtobufCoders.ProtobufFileSimpledCoder.instance);
|
||||
this.register(Serializable.class, ProtobufCoders.ProtobufSerializableSimpledCoder.instance);
|
||||
|
||||
this.register(Boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder2.instance);
|
||||
this.register(Byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder2.instance);
|
||||
this.register(Character[].class, ProtobufCoders.ProtobufCharArraySimpledCoder2.instance);
|
||||
this.register(Short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder2.instance);
|
||||
this.register(Integer[].class, ProtobufCoders.ProtobufIntArraySimpledCoder2.instance);
|
||||
this.register(Float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder2.instance);
|
||||
this.register(Long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder2.instance);
|
||||
this.register(Double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder2.instance);
|
||||
this.register(boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder.instance);
|
||||
this.register(byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder.instance);
|
||||
this.register(char[].class, ProtobufCoders.ProtobufCharArraySimpledCoder.instance);
|
||||
this.register(short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder.instance);
|
||||
this.register(int[].class, ProtobufCoders.ProtobufIntArraySimpledCoder.instance);
|
||||
this.register(float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder.instance);
|
||||
this.register(long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder.instance);
|
||||
this.register(double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder.instance);
|
||||
|
||||
this.register(String[].class, this.createArrayDecoder(String[].class));
|
||||
this.register(String[].class, this.createArrayEncoder(String[].class));
|
||||
}
|
||||
this.register(Boolean[].class, ProtobufCoders.ProtobufBoolArraySimpledCoder2.instance);
|
||||
this.register(Byte[].class, ProtobufCoders.ProtobufByteArraySimpledCoder2.instance);
|
||||
this.register(Character[].class, ProtobufCoders.ProtobufCharArraySimpledCoder2.instance);
|
||||
this.register(Short[].class, ProtobufCoders.ProtobufShortArraySimpledCoder2.instance);
|
||||
this.register(Integer[].class, ProtobufCoders.ProtobufIntArraySimpledCoder2.instance);
|
||||
this.register(Float[].class, ProtobufCoders.ProtobufFloatArraySimpledCoder2.instance);
|
||||
this.register(Long[].class, ProtobufCoders.ProtobufLongArraySimpledCoder2.instance);
|
||||
this.register(Double[].class, ProtobufCoders.ProtobufDoubleArraySimpledCoder2.instance);
|
||||
|
||||
this.register(String[].class, this.createArrayDecoder(String[].class));
|
||||
this.register(String[].class, this.createArrayEncoder(String[].class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.*;
|
||||
import java.util.function.*;
|
||||
import org.redkale.annotation.ConstructorParameters;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonArray;
|
||||
import org.redkale.convert.json.JsonObject;
|
||||
import static org.redkale.util.Utility.isEmpty;
|
||||
@@ -98,7 +99,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
|
||||
static Entry<AnyValue>[] getEntryAnyValueArray(
|
||||
BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String name) {
|
||||
BiPredicate<String, String> comparison, Entry<AnyValue>[] entitys, String name) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
@@ -110,7 +111,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
Entry[] rs = new Entry[len];
|
||||
int i = 0;
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
for (Entry<AnyValue> en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en;
|
||||
}
|
||||
@@ -139,7 +140,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
|
||||
static AnyValue[] getAnyValueArray(
|
||||
BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String name) {
|
||||
BiPredicate<String, String> comparison, Entry<AnyValue>[] entitys, String name) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
@@ -151,7 +152,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
AnyValue[] rs = new AnyValue[len];
|
||||
int i = 0;
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
for (Entry<AnyValue> en : entitys) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en.value;
|
||||
}
|
||||
@@ -187,7 +188,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
|
||||
static AnyValue[] getAnyValueArray(
|
||||
BiPredicate<String, String> comparison, Entry<AnyValueWriter>[] entitys, String... names) {
|
||||
BiPredicate<String, String> comparison, Entry<AnyValue>[] entitys, String... names) {
|
||||
int len = 0;
|
||||
for (Entry en : entitys) {
|
||||
for (String name : names) {
|
||||
@@ -202,7 +203,7 @@ public abstract class AnyValue {
|
||||
}
|
||||
AnyValue[] rs = new AnyValue[len];
|
||||
int i = 0;
|
||||
for (Entry<AnyValueWriter> en : entitys) {
|
||||
for (Entry<AnyValue> en : entitys) {
|
||||
for (String name : names) {
|
||||
if (comparison.test(en.name, name)) {
|
||||
rs[i++] = en.value;
|
||||
@@ -663,6 +664,7 @@ public abstract class AnyValue {
|
||||
*
|
||||
* @return String[]
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public abstract String[] getNames();
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
private Entry<String>[] stringEntrys = new Entry[0];
|
||||
|
||||
@ConvertColumn(index = 3)
|
||||
private Entry<AnyValueWriter>[] anyEntrys = new Entry[0];
|
||||
private Entry<AnyValue>[] anyEntrys = new Entry[0];
|
||||
|
||||
int parentArrayIndex = -1; // 只可能被loadFromProperties方法赋值
|
||||
|
||||
@@ -130,7 +130,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
if (this.anyEntrys != null) {
|
||||
rs.anyEntrys = new Entry[this.anyEntrys.length];
|
||||
for (int i = 0; i < rs.anyEntrys.length; i++) {
|
||||
Entry<AnyValueWriter> en = this.anyEntrys[i];
|
||||
Entry<AnyValue> en = this.anyEntrys[i];
|
||||
if (en == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
}
|
||||
}
|
||||
if (node.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : node.anyEntrys) {
|
||||
for (Entry<AnyValue> en : node.anyEntrys) {
|
||||
if (en == null || en.value == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -202,7 +202,8 @@ public class AnyValueWriter extends AnyValue {
|
||||
continue;
|
||||
}
|
||||
if (item.value != null
|
||||
&& en.value.parentArrayIndex == ((AnyValueWriter) item.value).parentArrayIndex) {
|
||||
&& ((AnyValueWriter) en.value).parentArrayIndex
|
||||
== ((AnyValueWriter) item.value).parentArrayIndex) {
|
||||
if (func == null) {
|
||||
item.value.merge(en.value, func);
|
||||
ok = true;
|
||||
@@ -274,7 +275,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : adv.anyEntrys) {
|
||||
for (Entry<AnyValue> en : adv.anyEntrys) {
|
||||
this.addValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
@@ -314,7 +315,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
}
|
||||
}
|
||||
if (adv.anyEntrys != null) {
|
||||
for (Entry<AnyValueWriter> en : adv.anyEntrys) {
|
||||
for (Entry<AnyValue> en : adv.anyEntrys) {
|
||||
this.setValue(en.name, en.value);
|
||||
}
|
||||
}
|
||||
@@ -372,7 +373,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
return (Entry<AnyValue>[]) (Entry[]) anyEntrys;
|
||||
}
|
||||
|
||||
public void setAnyEntrys(Entry<AnyValueWriter>[] anyEntrys) {
|
||||
public void setAnyEntrys(Entry<AnyValue>[] anyEntrys) {
|
||||
this.anyEntrys = anyEntrys;
|
||||
}
|
||||
|
||||
@@ -473,7 +474,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
if (!existsValue(name)) {
|
||||
this.addValue(name, value);
|
||||
} else {
|
||||
for (Entry<AnyValueWriter> en : this.anyEntrys) {
|
||||
for (Entry<AnyValue> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
en.value = (AnyValueWriter) value;
|
||||
return this;
|
||||
@@ -571,7 +572,7 @@ public class AnyValueWriter extends AnyValue {
|
||||
|
||||
@Override
|
||||
public AnyValue getAnyValue(String name, boolean create) {
|
||||
for (Entry<AnyValueWriter> en : this.anyEntrys) {
|
||||
for (Entry<AnyValue> en : this.anyEntrys) {
|
||||
if (predicate.test(en.name, name)) {
|
||||
return en.value;
|
||||
}
|
||||
|
||||
@@ -8,37 +8,48 @@ package org.redkale.test.convert.json;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/** @author zhangjx */
|
||||
public class DyncJsonTest {
|
||||
|
||||
private boolean main;
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
DyncJsonTest test = new DyncJsonTest();
|
||||
test.main = true;
|
||||
test.run();
|
||||
test.run1();
|
||||
test.run2();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
public void run1() throws Exception {
|
||||
SimpleDyncBean bean = new SimpleDyncBean();
|
||||
bean.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean));
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean));
|
||||
|
||||
SimpleDyncBean2 bean2 = new SimpleDyncBean2();
|
||||
bean2.name = "haha";
|
||||
|
||||
System.out.println(JsonConvert.root().convertTo(bean2));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean2));
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean2));
|
||||
SimpleDyncBean3 bean3 = new SimpleDyncBean3();
|
||||
bean3.name = "haha";
|
||||
System.out.println(JsonConvert.root().convertTo(bean3));
|
||||
if (!main)
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean3));
|
||||
Assertions.assertEquals("{\"name\":\"haha\"}", JsonConvert.root().convertTo(bean3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run2() throws Exception {
|
||||
AnyValueWriter writer = AnyValueWriter.create();
|
||||
writer.addValue("name", "aaa");
|
||||
writer.addValue("name", "bbb");
|
||||
writer.addValue("node", AnyValueWriter.create("id", "123"));
|
||||
writer.addValue("node", AnyValueWriter.create("id", "456"));
|
||||
System.out.println(writer);
|
||||
String bs = JsonConvert.root().convertTo(AnyValue.class, writer);
|
||||
AnyValue other = JsonConvert.root().convertFrom(AnyValue.class, bs);
|
||||
System.out.println(other);
|
||||
Assertions.assertEquals(writer.toString(), other.toString());
|
||||
}
|
||||
|
||||
public static class SimpleDyncBean {
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
*/
|
||||
package org.redkale.test.convert.pb;
|
||||
|
||||
import org.redkale.test.convert.User;
|
||||
import java.io.Serializable;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.convert.pb.ProtobufArrayEncoder;
|
||||
import org.redkale.convert.pb.ProtobufConvert;
|
||||
import org.redkale.convert.pb.ProtobufFactory;
|
||||
import org.redkale.convert.pb.ProtobufObjectEncoder;
|
||||
import org.redkale.test.convert.User;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.AnyValueWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -20,12 +25,13 @@ public class UserTest {
|
||||
|
||||
public static void main(String[] args) throws Throwable {
|
||||
UserTest test = new UserTest();
|
||||
test.run();
|
||||
test.run1();
|
||||
test.run2();
|
||||
test.run3();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
public void run1() throws Exception {
|
||||
User user = User.create();
|
||||
ProtobufConvert convert = ProtobufConvert.root();
|
||||
byte[] bytes = convert.convertTo(user);
|
||||
@@ -47,6 +53,26 @@ public class UserTest {
|
||||
Assertions.assertEquals(bean.toString(), bean2.toString());
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void run3() throws Exception {
|
||||
ProtobufFactory factory = ProtobufFactory.root();
|
||||
AnyValueWriter writer = AnyValueWriter.create();
|
||||
writer.addValue("name", "aaa");
|
||||
writer.addValue("name", "bbb");
|
||||
writer.addValue("node", AnyValueWriter.create("id", "123"));
|
||||
writer.addValue("node", AnyValueWriter.create("id", "456"));
|
||||
System.out.println(writer);
|
||||
ProtobufObjectEncoder encoder = (ProtobufObjectEncoder) factory.loadEncoder(AnyValueWriter.class);
|
||||
System.out.println(encoder);
|
||||
ProtobufArrayEncoder stringEntrys = (ProtobufArrayEncoder) encoder.getMembers()[2].getEncoder();
|
||||
System.out.println(stringEntrys);
|
||||
byte[] bs = factory.getConvert().convertTo(AnyValue.class, writer);
|
||||
System.out.println("长度: " + bs.length);
|
||||
AnyValue other = factory.getConvert().convertFrom(AnyValue.class, bs);
|
||||
System.out.println(other);
|
||||
Assertions.assertEquals(writer.toString(), other.toString());
|
||||
}
|
||||
|
||||
public static class InnerBean {
|
||||
|
||||
@ConvertColumn(index = 1)
|
||||
|
||||
Reference in New Issue
Block a user