【不兼容】BSON格式升级,兼容子类数据转父类对象
This commit is contained in:
@@ -8,6 +8,7 @@ package org.redkale.convert.bson;
|
||||
import java.nio.*;
|
||||
import org.redkale.convert.*;
|
||||
import static org.redkale.convert.Reader.SIGN_NULL;
|
||||
import org.redkale.convert.ext.ByteSimpledCoder;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,12 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
short bt = readShort();
|
||||
if (bt == Reader.SIGN_NULL) return bt;
|
||||
short lt = readShort();
|
||||
byte kt = readByte();
|
||||
byte vt = readByte();
|
||||
if (typevals != null) {
|
||||
typevals[0] = kt;
|
||||
typevals[1] = vt;
|
||||
}
|
||||
return (bt & 0xffff) << 16 | (lt & 0xffff);
|
||||
}
|
||||
|
||||
@@ -70,6 +77,10 @@ public class BsonByteBufferReader extends BsonReader {
|
||||
short bt = readShort();
|
||||
if (bt == Reader.SIGN_NULL) return bt;
|
||||
short lt = readShort();
|
||||
if (componentDecoder != null && componentDecoder != ByteSimpledCoder.instance) {
|
||||
byte comval = readByte();
|
||||
if (typevals != null) typevals[0] = comval;
|
||||
}
|
||||
return (bt & 0xffff) << 16 | (lt & 0xffff);
|
||||
}
|
||||
//------------------------------------------------------------
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.redkale.convert.bson;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
import org.redkale.convert.*;
|
||||
@@ -29,65 +30,15 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||
|
||||
static final Encodeable objectEncoder = instance.loadEncoder(Object.class);
|
||||
|
||||
static final Decodeable collectionBooleanDecoder = instance.loadDecoder(new TypeToken<Collection<Boolean>>() {
|
||||
static final Decodeable skipArrayDecoder = new SkipArrayDecoder(instance, Object[].class);
|
||||
|
||||
static final Decodeable skipCollectionDecoder = new SkipCollectionDecoder(instance, new TypeToken<Collection<Object>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionByteDecoder = instance.loadDecoder(new TypeToken<Collection<Byte>>() {
|
||||
static final Decodeable skipStreamDecoder = new SkipStreamDecoder(instance, new TypeToken<Stream<Object>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionShortDecoder = instance.loadDecoder(new TypeToken<Collection<Short>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionCharacterDecoder = instance.loadDecoder(new TypeToken<Collection<Character>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionIntegerDecoder = instance.loadDecoder(new TypeToken<Collection<Integer>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionLongDecoder = instance.loadDecoder(new TypeToken<Collection<Long>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionFloatDecoder = instance.loadDecoder(new TypeToken<Collection<Float>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionDoubleDecoder = instance.loadDecoder(new TypeToken<Collection<Double>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionStringDecoder = instance.loadDecoder(new TypeToken<Collection<String>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable collectionObjectDecoder = instance.loadDecoder(new TypeToken<Collection<Object>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringBooleanDecoder = instance.loadDecoder(new TypeToken<Map<String, Boolean>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringByteDecoder = instance.loadDecoder(new TypeToken<Map<String, Byte>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringShortDecoder = instance.loadDecoder(new TypeToken<Map<String, Short>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringCharacterDecoder = instance.loadDecoder(new TypeToken<Map<String, Character>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringIntegerDecoder = instance.loadDecoder(new TypeToken<Map<String, Integer>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringLongDecoder = instance.loadDecoder(new TypeToken<Map<String, Long>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringFloatDecoder = instance.loadDecoder(new TypeToken<Map<String, Float>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringDoubleDecoder = instance.loadDecoder(new TypeToken<Map<String, Double>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringStringDecoder = instance.loadDecoder(new TypeToken<Map<String, String>>() {
|
||||
}.getType());
|
||||
|
||||
static final Decodeable mapStringObjectDecoder = instance.loadDecoder(new TypeToken<Map<String, Object>>() {
|
||||
}.getType());
|
||||
static final Decodeable skipMapDecoder = new SkipMapDecoder(instance, Map.class);
|
||||
|
||||
static {
|
||||
instance.register(Serializable.class, objectDecoder);
|
||||
@@ -152,6 +103,10 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static byte typeEnum(final Type type) {
|
||||
return typeEnum(TypeToken.typeToClass(type));
|
||||
}
|
||||
|
||||
protected static byte typeEnum(final Class type) {
|
||||
Objects.requireNonNull(type);
|
||||
byte typeval = 127; //字段的类型值
|
||||
@@ -241,8 +196,17 @@ public final class BsonFactory extends ConvertFactory<BsonReader, BsonWriter> {
|
||||
return DoubleArraySimpledCoder.instance;
|
||||
case 29:
|
||||
return StringArraySimpledCoder.instance;
|
||||
default:
|
||||
case 81:
|
||||
return skipArrayDecoder;
|
||||
case 82:
|
||||
return skipCollectionDecoder;
|
||||
case 83:
|
||||
return skipStreamDecoder;
|
||||
case 84:
|
||||
return skipMapDecoder;
|
||||
case 127:
|
||||
return BsonFactory.objectDecoder;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,113 +93,27 @@ public class BsonReader extends Reader {
|
||||
final byte val = this.typeval;
|
||||
this.typeval = 0;
|
||||
switch (val) {
|
||||
case 1: readBoolean();
|
||||
case 11: readBoolean();
|
||||
break;
|
||||
case 2: readByte();
|
||||
case 12: readByte();
|
||||
break;
|
||||
case 3: readShort();
|
||||
case 13: readShort();
|
||||
break;
|
||||
case 4: readChar();
|
||||
case 14: readChar();
|
||||
break;
|
||||
case 5: readInt();
|
||||
case 15: readInt();
|
||||
break;
|
||||
case 6: readLong();
|
||||
case 16: readLong();
|
||||
break;
|
||||
case 7: readFloat();
|
||||
case 17: readFloat();
|
||||
break;
|
||||
case 8: readDouble();
|
||||
case 18: readDouble();
|
||||
break;
|
||||
case 9: readString();
|
||||
case 19: readString();
|
||||
break;
|
||||
case 20:
|
||||
BsonFactory.collectionObjectDecoder.convertFrom(this);
|
||||
break;
|
||||
case 21:
|
||||
BsonFactory.collectionBooleanDecoder.convertFrom(this);
|
||||
break;
|
||||
case 22:
|
||||
BsonFactory.collectionByteDecoder.convertFrom(this);
|
||||
break;
|
||||
case 23:
|
||||
BsonFactory.collectionShortDecoder.convertFrom(this);
|
||||
break;
|
||||
case 24:
|
||||
BsonFactory.collectionCharacterDecoder.convertFrom(this);
|
||||
break;
|
||||
case 25:
|
||||
BsonFactory.collectionIntegerDecoder.convertFrom(this);
|
||||
break;
|
||||
case 26:
|
||||
BsonFactory.collectionLongDecoder.convertFrom(this);
|
||||
break;
|
||||
case 27:
|
||||
BsonFactory.collectionFloatDecoder.convertFrom(this);
|
||||
break;
|
||||
case 28:
|
||||
BsonFactory.collectionDoubleDecoder.convertFrom(this);
|
||||
break;
|
||||
case 29:
|
||||
BsonFactory.collectionStringDecoder.convertFrom(this);
|
||||
break;
|
||||
case 40:
|
||||
BsonFactory.mapStringObjectDecoder.convertFrom(this);
|
||||
break;
|
||||
case 41:
|
||||
BsonFactory.mapStringBooleanDecoder.convertFrom(this);
|
||||
break;
|
||||
case 42:
|
||||
BsonFactory.mapStringByteDecoder.convertFrom(this);
|
||||
break;
|
||||
case 43:
|
||||
BsonFactory.mapStringShortDecoder.convertFrom(this);
|
||||
break;
|
||||
case 44:
|
||||
BsonFactory.mapStringCharacterDecoder.convertFrom(this);
|
||||
break;
|
||||
case 45:
|
||||
BsonFactory.mapStringIntegerDecoder.convertFrom(this);
|
||||
break;
|
||||
case 46:
|
||||
BsonFactory.mapStringLongDecoder.convertFrom(this);
|
||||
break;
|
||||
case 47:
|
||||
BsonFactory.mapStringFloatDecoder.convertFrom(this);
|
||||
break;
|
||||
case 48:
|
||||
BsonFactory.mapStringDoubleDecoder.convertFrom(this);
|
||||
break;
|
||||
case 49:
|
||||
BsonFactory.mapStringStringDecoder.convertFrom(this);
|
||||
break;
|
||||
case 101:
|
||||
BoolArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 102:
|
||||
ByteArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 103:
|
||||
ShortArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 104:
|
||||
CharArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 105:
|
||||
IntArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 106:
|
||||
LongArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 107:
|
||||
FloatArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 108:
|
||||
DoubleArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 109:
|
||||
StringArraySimpledCoder.instance.convertFrom(this);
|
||||
break;
|
||||
case 127:
|
||||
BsonFactory.objectDecoder.convertFrom(this);
|
||||
default:
|
||||
Decodeable decoder = BsonFactory.typeEnum(val);
|
||||
if (decoder != null) decoder.convertFrom(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -234,7 +148,14 @@ public class BsonReader extends Reader {
|
||||
public int readMapB(DeMember member, byte[] typevals, Decodeable keyDecoder, Decodeable valueDecoder) {
|
||||
short bt = readShort();
|
||||
if (bt == Reader.SIGN_NULL) return bt;
|
||||
return (bt & 0xffff) << 16 | ((content[++this.position] & 0xff) << 8) | (content[++this.position] & 0xff);
|
||||
int rs = (bt & 0xffff) << 16 | ((content[++this.position] & 0xff) << 8) | (content[++this.position] & 0xff);
|
||||
byte kt = readByte();
|
||||
byte vt = readByte();
|
||||
if (typevals != null) {
|
||||
typevals[0] = kt;
|
||||
typevals[1] = vt;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,7 +172,10 @@ public class BsonReader extends Reader {
|
||||
short bt = readShort();
|
||||
if (bt == Reader.SIGN_NULL) return bt;
|
||||
int rs = (bt & 0xffff) << 16 | ((content[++this.position] & 0xff) << 8) | (content[++this.position] & 0xff);
|
||||
if (componentDecoder == null || componentDecoder == ByteSimpledCoder.instance) return rs; //byte[]
|
||||
if (componentDecoder != null && componentDecoder != ByteSimpledCoder.instance) {
|
||||
byte comval = readByte();
|
||||
if (typevals != null) typevals[0] = comval;
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ package org.redkale.convert.bson;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.redkale.convert.*;
|
||||
import org.redkale.convert.ext.ByteSimpledCoder;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -201,98 +202,7 @@ public class BsonWriter extends Writer {
|
||||
Attribute attribute = member.getAttribute();
|
||||
writeByte(BsonReader.SIGN_HASNEXT);
|
||||
writeSmallString(attribute.field());
|
||||
byte typeval = 127; //字段的类型值
|
||||
final Class type = attribute.type();
|
||||
if (type == boolean.class || type == Boolean.class) {
|
||||
typeval = 1;
|
||||
} else if (type == byte.class || type == Byte.class) {
|
||||
typeval = 2;
|
||||
} else if (type == short.class || type == Short.class) {
|
||||
typeval = 3;
|
||||
} else if (type == char.class || type == Character.class) {
|
||||
typeval = 4;
|
||||
} else if (type == int.class || type == Integer.class) {
|
||||
typeval = 5;
|
||||
} else if (type == long.class || type == Long.class) {
|
||||
typeval = 6;
|
||||
} else if (type == float.class || type == Float.class) {
|
||||
typeval = 7;
|
||||
} else if (type == double.class || type == Double.class) {
|
||||
typeval = 8;
|
||||
} else if (type == String.class) {
|
||||
typeval = 9;
|
||||
} else if (type == boolean[].class || type == Boolean[].class) {
|
||||
typeval = 101;
|
||||
} else if (type == byte[].class || type == Byte[].class) {
|
||||
typeval = 102;
|
||||
} else if (type == short[].class || type == Short[].class) {
|
||||
typeval = 103;
|
||||
} else if (type == char[].class || type == Character[].class) {
|
||||
typeval = 104;
|
||||
} else if (type == int[].class || type == Integer[].class) {
|
||||
typeval = 105;
|
||||
} else if (type == long[].class || type == Long[].class) {
|
||||
typeval = 106;
|
||||
} else if (type == float[].class || type == Float[].class) {
|
||||
typeval = 107;
|
||||
} else if (type == double[].class || type == Double[].class) {
|
||||
typeval = 108;
|
||||
} else if (type == String[].class) {
|
||||
typeval = 109;
|
||||
}
|
||||
if (typeval == 127 && member.getEncoder() instanceof CollectionEncoder) {
|
||||
java.lang.reflect.Type comType = ((CollectionEncoder) member.getEncoder()).getComponentEncoder().getType();
|
||||
if (comType == Boolean.class) {
|
||||
typeval = 21;
|
||||
} else if (comType == Byte.class) {
|
||||
typeval = 22;
|
||||
} else if (comType == Short.class) {
|
||||
typeval = 23;
|
||||
} else if (comType == Character.class) {
|
||||
typeval = 24;
|
||||
} else if (comType == Integer.class) {
|
||||
typeval = 25;
|
||||
} else if (comType == Long.class) {
|
||||
typeval = 26;
|
||||
} else if (comType == Float.class) {
|
||||
typeval = 27;
|
||||
} else if (comType == Double.class) {
|
||||
typeval = 28;
|
||||
} else if (comType == String.class) {
|
||||
typeval = 29;
|
||||
} else {
|
||||
typeval = 20;
|
||||
}
|
||||
}
|
||||
if (typeval == 127 && member.getEncoder() instanceof ArrayEncoder) {
|
||||
typeval = 20;
|
||||
}
|
||||
if (typeval == 127 && member.getEncoder() instanceof MapEncoder) {
|
||||
java.lang.reflect.Type keyType = ((MapEncoder) member.getEncoder()).getKeyEncoder().getType();
|
||||
java.lang.reflect.Type valType = ((MapEncoder) member.getEncoder()).getValueEncoder().getType();
|
||||
if (keyType == String.class && valType == Boolean.class) {
|
||||
typeval = 41;
|
||||
} else if (keyType == String.class && valType == Byte.class) {
|
||||
typeval = 42;
|
||||
} else if (keyType == String.class && valType == Short.class) {
|
||||
typeval = 43;
|
||||
} else if (keyType == String.class && valType == Character.class) {
|
||||
typeval = 44;
|
||||
} else if (keyType == String.class && valType == Integer.class) {
|
||||
typeval = 45;
|
||||
} else if (keyType == String.class && valType == Long.class) {
|
||||
typeval = 46;
|
||||
} else if (keyType == String.class && valType == Float.class) {
|
||||
typeval = 47;
|
||||
} else if (keyType == String.class && valType == Double.class) {
|
||||
typeval = 48;
|
||||
} else if (keyType == String.class && valType == String.class) {
|
||||
typeval = 49;
|
||||
} else if (keyType == String.class) {
|
||||
typeval = 40;
|
||||
}
|
||||
}
|
||||
writeByte(typeval);
|
||||
writeByte(BsonFactory.typeEnum(attribute.type()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,6 +249,9 @@ public class BsonWriter extends Writer {
|
||||
@Override
|
||||
public final int writeArrayB(int size, Encodeable<Writer, Object> componentEncoder, Object obj) {
|
||||
writeInt(size);
|
||||
if (componentEncoder != null && componentEncoder != ByteSimpledCoder.instance) {
|
||||
writeByte(BsonFactory.typeEnum(componentEncoder.getType()));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -353,6 +266,8 @@ public class BsonWriter extends Writer {
|
||||
@Override
|
||||
public int writeMapB(int size, Encodeable<Writer, Object> keyEncoder, Encodeable<Writer, Object> valueEncoder, Object obj) {
|
||||
writeInt(size);
|
||||
writeByte(BsonFactory.typeEnum(keyEncoder.getType()));
|
||||
writeByte(BsonFactory.typeEnum(valueEncoder.getType()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
33
src/org/redkale/convert/bson/SkipArrayDecoder.java
Normal file
33
src/org/redkale/convert/bson/SkipArrayDecoder.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.bson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
* 数组的反序列化操作类 <br>
|
||||
* 对象数组的反序列化,不包含int[]、long[]这样的primitive class数组。 <br>
|
||||
* 支持一定程度的泛型。 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T> 反解析的数组元素类型
|
||||
*/
|
||||
public class SkipArrayDecoder<T> extends ArrayDecoder<T> {
|
||||
|
||||
public SkipArrayDecoder(final ConvertFactory factory, final Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Decodeable<Reader, T> getComponentDecoder(Decodeable<Reader, T> decoder, byte[] typevals) {
|
||||
if (typevals != null) return BsonFactory.typeEnum(typevals[0]);
|
||||
return decoder;
|
||||
}
|
||||
}
|
||||
32
src/org/redkale/convert/bson/SkipCollectionDecoder.java
Normal file
32
src/org/redkale/convert/bson/SkipCollectionDecoder.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.bson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
* Collection的反序列化操作类 <br>
|
||||
* 支持一定程度的泛型。 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T> 反解析的集合元素类型
|
||||
*/
|
||||
public class SkipCollectionDecoder<T> extends CollectionDecoder<T> {
|
||||
|
||||
public SkipCollectionDecoder(final ConvertFactory factory, final Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Decodeable<Reader, T> getComponentDecoder(Decodeable<Reader, T> decoder, byte[] typevals) {
|
||||
if (typevals != null) return BsonFactory.typeEnum(typevals[0]);
|
||||
return decoder;
|
||||
}
|
||||
}
|
||||
38
src/org/redkale/convert/bson/SkipMapDecoder.java
Normal file
38
src/org/redkale/convert/bson/SkipMapDecoder.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.bson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
* Map的反序列化操作类 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <K> Map key的数据类型
|
||||
* @param <V> Map value的数据类型
|
||||
*/
|
||||
public class SkipMapDecoder<K, V> extends MapDecoder<K, V> {
|
||||
|
||||
public SkipMapDecoder(final ConvertFactory factory, final Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Decodeable<Reader, K> getKeyDecoder(Decodeable<Reader, K> decoder, byte[] typevals) {
|
||||
if (typevals != null) return BsonFactory.typeEnum(typevals[0]);
|
||||
return decoder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Decodeable<Reader, V> getValueDecoder(Decodeable<Reader, V> decoder, byte[] typevals) {
|
||||
if (typevals != null) return BsonFactory.typeEnum(typevals[1]);
|
||||
return decoder;
|
||||
}
|
||||
}
|
||||
32
src/org/redkale/convert/bson/SkipStreamDecoder.java
Normal file
32
src/org/redkale/convert/bson/SkipStreamDecoder.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.bson;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.redkale.convert.*;
|
||||
|
||||
/**
|
||||
* Stream的反序列化操作类 <br>
|
||||
* 支持一定程度的泛型。 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T> 反解析的集合元素类型
|
||||
*/
|
||||
public class SkipStreamDecoder<T> extends StreamDecoder<T> {
|
||||
|
||||
public SkipStreamDecoder(final ConvertFactory factory, final Type type) {
|
||||
super(factory, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Decodeable<Reader, T> getComponentDecoder(Decodeable<Reader, T> decoder, byte[] typevals) {
|
||||
if (typevals != null) return BsonFactory.typeEnum(typevals[0]);
|
||||
return decoder;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.*;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.logging.*;
|
||||
import java.util.stream.Stream;
|
||||
import org.redkale.asm.*;
|
||||
import org.redkale.asm.Type;
|
||||
import static org.redkale.asm.Opcodes.*;
|
||||
@@ -81,6 +82,7 @@ public interface Creator<T> {
|
||||
creatorCacheMap.put(ArrayList.class, (params) -> new ArrayList<>());
|
||||
creatorCacheMap.put(HashMap.class, (params) -> new HashMap<>());
|
||||
creatorCacheMap.put(HashSet.class, (params) -> new HashSet<>());
|
||||
creatorCacheMap.put(Stream.class, (params) -> new ArrayList<>().stream());
|
||||
creatorCacheMap.put(ConcurrentHashMap.class, (params) -> new ConcurrentHashMap<>());
|
||||
creatorCacheMap.put(CompletableFuture.class, (params) -> new CompletableFuture<>());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user