diff --git a/src/main/java/org/redkale/convert/ConvertFactory.java b/src/main/java/org/redkale/convert/ConvertFactory.java index 74c5fcdd6..712fc0ac5 100644 --- a/src/main/java/org/redkale/convert/ConvertFactory.java +++ b/src/main/java/org/redkale/convert/ConvertFactory.java @@ -122,6 +122,7 @@ public abstract class ConvertFactory { 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); diff --git a/src/main/java/org/redkale/convert/bson/BsonArrayDecoder.java b/src/main/java/org/redkale/convert/bson/BsonArrayDecoder.java index e4072be34..2a68063ab 100644 --- a/src/main/java/org/redkale/convert/bson/BsonArrayDecoder.java +++ b/src/main/java/org/redkale/convert/bson/BsonArrayDecoder.java @@ -21,8 +21,11 @@ import org.redkale.convert.*; */ public class BsonArrayDecoder extends ArrayDecoder { - public BsonArrayDecoder(final BsonFactory factory, final Type type) { + private final boolean skip; + + public BsonArrayDecoder(final BsonFactory factory, final Type type, boolean skip) { super(factory, type); + this.skip = skip; } @Override @@ -32,7 +35,10 @@ public class BsonArrayDecoder extends ArrayDecoder { if (len == Reader.SIGN_NULL) { return null; } - final Decodeable itemDecoder = BsonFactory.typeEnum(in.readArrayItemTypeEnum()); + Decodeable itemDecoder = this.componentDecoder; + if (skip) { + itemDecoder = BsonFactory.skipTypeEnum(in.readArrayItemTypeEnum()); + } final List result = new ArrayList(); // 固定长度 for (int i = 0; i < len; i++) { diff --git a/src/main/java/org/redkale/convert/bson/BsonCollectionDecoder.java b/src/main/java/org/redkale/convert/bson/BsonCollectionDecoder.java index 83370e8ab..fe5ef170a 100644 --- a/src/main/java/org/redkale/convert/bson/BsonCollectionDecoder.java +++ b/src/main/java/org/redkale/convert/bson/BsonCollectionDecoder.java @@ -20,8 +20,11 @@ import org.redkale.convert.*; */ public class BsonCollectionDecoder extends CollectionDecoder { - public BsonCollectionDecoder(final ConvertFactory factory, final Type type) { + private final boolean skip; + + public BsonCollectionDecoder(final ConvertFactory factory, final Type type, boolean skip) { super(factory, type); + this.skip = skip; } @Override @@ -31,7 +34,10 @@ public class BsonCollectionDecoder extends CollectionDecoder { if (len == Reader.SIGN_NULL) { return null; } - final Decodeable itemDecoder = BsonFactory.typeEnum(in.readArrayItemTypeEnum()); + Decodeable itemDecoder = this.componentDecoder; + if (skip) { + itemDecoder = BsonFactory.skipTypeEnum(in.readArrayItemTypeEnum()); + } final Collection result = this.creator.create(); // 固定长度 for (int i = 0; i < len; i++) { diff --git a/src/main/java/org/redkale/convert/bson/BsonFactory.java b/src/main/java/org/redkale/convert/bson/BsonFactory.java index c74e1db09..ad02ee9f7 100644 --- a/src/main/java/org/redkale/convert/bson/BsonFactory.java +++ b/src/main/java/org/redkale/convert/bson/BsonFactory.java @@ -8,6 +8,9 @@ package org.redkale.convert.bson; import java.io.Serializable; import java.lang.reflect.Type; import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Stream; import org.redkale.convert.*; import org.redkale.convert.ext.*; @@ -37,16 +40,16 @@ public final class BsonFactory extends ConvertFactory { static final Encodeable objectEncoder = instance.loadEncoder(Object.class); // only for BsonRead.skipValue - static final Decodeable skipArrayDecoder = new BsonArrayDecoder(instance, Object[].class); + static final Decodeable skipArrayDecoder = new BsonArrayDecoder(instance, Object[].class, true); // only for BsonRead.skipValue - static final Decodeable skipCollectionDecoder = new BsonCollectionDecoder(instance, Collection.class); + static final Decodeable skipCollectionDecoder = new BsonCollectionDecoder(instance, Collection.class, true); // only for BsonRead.skipValue - static final Decodeable skipStreamDecoder = new BsonStreamDecoder(instance, Stream.class); + static final Decodeable skipStreamDecoder = new BsonStreamDecoder(instance, Stream.class, true); // only for BsonRead.skipValue - static final Decodeable skipMapDecoder = new BsonMapDecoder(instance, Map.class); + static final Decodeable skipMapDecoder = new BsonMapDecoder(instance, Map.class, true); static { instance.register(Serializable.class, objectDecoder); @@ -124,22 +127,22 @@ public final class BsonFactory extends ConvertFactory { @Override protected Decodeable createArrayDecoder(Type type) { - return new BsonArrayDecoder(this, type); + return new BsonArrayDecoder(this, type, false); } @Override protected Decodeable createCollectionDecoder(Type type) { - return new BsonCollectionDecoder(this, type); + return new BsonCollectionDecoder(this, type, false); } @Override protected Decodeable createStreamDecoder(Type type) { - return new BsonStreamDecoder(this, type); + return new BsonStreamDecoder(this, type, false); } @Override protected Decodeable createMapDecoder(Type type) { - return new BsonMapDecoder(this, type); + return new BsonMapDecoder(this, type, false); } @Override @@ -161,7 +164,7 @@ public final class BsonFactory extends ConvertFactory { Objects.requireNonNull(type); Class clazz = TypeToken.typeToClass(type); byte typeval = 127; // 字段的类型值 - if (clazz == boolean.class || clazz == Boolean.class) { + if (clazz == boolean.class || clazz == Boolean.class || clazz == AtomicBoolean.class) { typeval = 11; } else if (clazz == byte.class || clazz == Byte.class) { typeval = 12; @@ -169,9 +172,9 @@ public final class BsonFactory extends ConvertFactory { typeval = 13; } else if (clazz == char.class || clazz == Character.class) { typeval = 14; - } else if (clazz == int.class || clazz == Integer.class) { + } else if (clazz == int.class || clazz == Integer.class || clazz == AtomicInteger.class) { typeval = 15; - } else if (clazz == long.class || clazz == Long.class) { + } else if (clazz == long.class || clazz == Long.class || clazz == AtomicLong.class) { typeval = 16; } else if (clazz == float.class || clazz == Float.class) { typeval = 17; @@ -179,7 +182,7 @@ public final class BsonFactory extends ConvertFactory { typeval = 18; } else if (clazz == String.class) { typeval = 19; - } else if (clazz == boolean[].class || clazz == Boolean[].class) { + } else if (clazz == boolean[].class || clazz == Boolean[].class || clazz == AtomicBoolean[].class) { typeval = 21; } else if (clazz == byte[].class || clazz == Byte[].class) { typeval = 22; @@ -187,9 +190,9 @@ public final class BsonFactory extends ConvertFactory { typeval = 23; } else if (clazz == char[].class || clazz == Character[].class) { typeval = 24; - } else if (clazz == int[].class || clazz == Integer[].class) { + } else if (clazz == int[].class || clazz == Integer[].class || clazz == AtomicInteger[].class) { typeval = 25; - } else if (clazz == long[].class || clazz == Long[].class) { + } else if (clazz == long[].class || clazz == Long[].class || clazz == AtomicLong[].class) { typeval = 26; } else if (clazz == float[].class || clazz == Float[].class) { typeval = 27; @@ -209,7 +212,7 @@ public final class BsonFactory extends ConvertFactory { return typeval; } - protected static Decodeable typeEnum(final byte typeval) { + protected static Decodeable skipTypeEnum(final byte typeval) { switch (typeval) { case 11: return BoolSimpledCoder.instance; diff --git a/src/main/java/org/redkale/convert/bson/BsonMapDecoder.java b/src/main/java/org/redkale/convert/bson/BsonMapDecoder.java index 9da3ff6a4..4b90ed9a2 100644 --- a/src/main/java/org/redkale/convert/bson/BsonMapDecoder.java +++ b/src/main/java/org/redkale/convert/bson/BsonMapDecoder.java @@ -20,8 +20,11 @@ import org.redkale.convert.*; */ public class BsonMapDecoder extends MapDecoder { - public BsonMapDecoder(final BsonFactory factory, final Type type) { + private final boolean skip; + + public BsonMapDecoder(final BsonFactory factory, final Type type, boolean skip) { super(factory, type); + this.skip = skip; } @Override @@ -31,8 +34,12 @@ public class BsonMapDecoder extends MapDecoder { if (len == Reader.SIGN_NULL) { return null; } - Decodeable kdecoder = BsonFactory.typeEnum(in.readMapKeyTypeEnum()); - Decodeable vdecoder = BsonFactory.typeEnum(in.readmapValueTypeEnum()); + Decodeable kdecoder = this.keyDecoder; + Decodeable vdecoder = this.valueDecoder; + if (skip) { + kdecoder = BsonFactory.skipTypeEnum(in.readMapKeyTypeEnum()); + vdecoder = BsonFactory.skipTypeEnum(in.readmapValueTypeEnum()); + } final Map result = this.creator.create(); // 固定长度 for (int i = 0; i < len; i++) { diff --git a/src/main/java/org/redkale/convert/bson/BsonReader.java b/src/main/java/org/redkale/convert/bson/BsonReader.java index 878fa6684..998e9d58b 100644 --- a/src/main/java/org/redkale/convert/bson/BsonReader.java +++ b/src/main/java/org/redkale/convert/bson/BsonReader.java @@ -104,7 +104,7 @@ public class BsonReader extends Reader { return; } this.fieldTypeEnum = 0; - Decodeable decoder = BsonFactory.typeEnum(val); + Decodeable decoder = BsonFactory.skipTypeEnum(val); decoder.convertFrom(this); } diff --git a/src/main/java/org/redkale/convert/bson/BsonStreamDecoder.java b/src/main/java/org/redkale/convert/bson/BsonStreamDecoder.java index 7ba993b29..dde2bc508 100644 --- a/src/main/java/org/redkale/convert/bson/BsonStreamDecoder.java +++ b/src/main/java/org/redkale/convert/bson/BsonStreamDecoder.java @@ -21,8 +21,11 @@ import org.redkale.convert.*; */ public class BsonStreamDecoder extends StreamDecoder { - public BsonStreamDecoder(final BsonFactory factory, final Type type) { + private final boolean skip; + + public BsonStreamDecoder(final BsonFactory factory, final Type type, boolean skip) { super(factory, type); + this.skip = skip; } @Override @@ -32,7 +35,10 @@ public class BsonStreamDecoder extends StreamDecoder { if (len == Reader.SIGN_NULL) { return null; } - final Decodeable itemDecoder = BsonFactory.typeEnum(in.readArrayItemTypeEnum()); + Decodeable itemDecoder = this.componentDecoder; + if (skip) { + itemDecoder = BsonFactory.skipTypeEnum(in.readArrayItemTypeEnum()); + } final List result = new ArrayList(); // 固定长度 for (int i = 0; i < len; i++) { diff --git a/src/main/java/org/redkale/convert/ext/AtomicBooleanSimpledCoder.java b/src/main/java/org/redkale/convert/ext/AtomicBooleanSimpledCoder.java new file mode 100644 index 000000000..0ee1a7ad7 --- /dev/null +++ b/src/main/java/org/redkale/convert/ext/AtomicBooleanSimpledCoder.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016-2116 Redkale + * All rights reserved. + */ +package org.redkale.convert.ext; + +import java.util.concurrent.atomic.AtomicBoolean; +import org.redkale.convert.Reader; +import org.redkale.convert.SimpledCoder; +import org.redkale.convert.Writer; + +/** + * AtomicAtomicBoolean 的SimpledCoder实现 + * + *

详情见: https://redkale.org + * + * @author zhangjx + * @param Reader输入的子类型 + * @param Writer输出的子类型 + */ +public class AtomicBooleanSimpledCoder extends SimpledCoder { + + public static final AtomicBooleanSimpledCoder instance = new AtomicBooleanSimpledCoder(); + + @Override + public void convertTo(W out, AtomicBoolean value) { + out.writeBoolean(value != null && value.get()); + } + + @Override + public AtomicBoolean convertFrom(R in) { + return new AtomicBoolean(in.readBoolean()); + } +} diff --git a/src/main/java/org/redkale/convert/pb/ProtobufCoders.java b/src/main/java/org/redkale/convert/pb/ProtobufCoders.java index 19df8bac7..cb03e1686 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufCoders.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufCoders.java @@ -472,6 +472,27 @@ public abstract class ProtobufCoders { } } + public static class ProtobufAtomicBooleanCollectionSimpledCoder + extends SimpledCoder> + implements ProtobufPrimitivable { + + private final Creator creator; + + public ProtobufAtomicBooleanCollectionSimpledCoder(Creator creator) { + this.creator = creator; + } + + @Override + public void convertTo(ProtobufWriter out, Collection values) { + out.writeAtomicBooleans(values); + } + + @Override + public Collection convertFrom(ProtobufReader in) { + return in.readAtomicBooleans(creator); + } + } + public static class ProtobufAtomicIntegerCollectionSimpledCoder extends SimpledCoder> implements ProtobufPrimitivable { @@ -642,6 +663,24 @@ public abstract class ProtobufCoders { } } + public static class ProtobufAtomicBooleanStreamSimpledCoder + extends SimpledCoder> + implements ProtobufPrimitivable { + + public static final ProtobufAtomicBooleanStreamSimpledCoder instance = + new ProtobufAtomicBooleanStreamSimpledCoder(); + + @Override + public void convertTo(ProtobufWriter out, Stream values) { + out.writeAtomicBooleans(values); + } + + @Override + public Stream convertFrom(ProtobufReader in) { + return in.readAtomicBooleans(LIST_CREATOR).stream(); + } + } + public static class ProtobufAtomicIntegerStreamSimpledCoder extends SimpledCoder> implements ProtobufPrimitivable { diff --git a/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java b/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java index 88e12fa75..05194e269 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufDynEncoder.java @@ -238,6 +238,8 @@ public abstract class ProtobufDynEncoder extends ProtobufObjectEncoder { wmethodName = "writeFieldLongsValue"; } else if (componentType == Double.class) { wmethodName = "writeFieldDoublesValue"; + } else if (componentType == AtomicBoolean.class) { + wmethodName = "writeFieldAtomicBooleansValue"; } else if (componentType == AtomicInteger.class) { wmethodName = "writeFieldAtomicIntegersValue"; } else if (componentType == AtomicLong.class) { diff --git a/src/main/java/org/redkale/convert/pb/ProtobufFactory.java b/src/main/java/org/redkale/convert/pb/ProtobufFactory.java index a52a846a5..2ff32032a 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufFactory.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufFactory.java @@ -11,6 +11,8 @@ import java.util.*; import java.util.concurrent.atomic.*; import java.util.stream.Stream; import org.redkale.convert.*; +import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicBooleanCollectionSimpledCoder; +import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicBooleanStreamSimpledCoder; import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicIntegerArraySimpledCoder; import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicIntegerCollectionSimpledCoder; import org.redkale.convert.pb.ProtobufCoders.ProtobufAtomicIntegerStreamSimpledCoder; @@ -214,6 +216,9 @@ public class ProtobufFactory extends ConvertFactory creator = loadCreator((Class) pt.getRawType()); return (Decodeable) new ProtobufDoubleCollectionSimpledCoder(creator); + } else if (componentType == AtomicBoolean.class) { + Creator creator = loadCreator((Class) pt.getRawType()); + return (Decodeable) new ProtobufAtomicBooleanCollectionSimpledCoder(creator); } else if (componentType == AtomicInteger.class) { Creator creator = loadCreator((Class) pt.getRawType()); return (Decodeable) new ProtobufAtomicIntegerCollectionSimpledCoder(creator); @@ -247,6 +252,8 @@ public class ProtobufFactory extends ConvertFactory>> 6; } protected static int computeSInt32SizeNoTag(final int value) { - if (value == 0) { - return 1; - } + if (value == 0) return 1; return computeUInt32SizeNoTag(encodeZigZag32(value)); } - protected static int computeSInt64SizeNoTag(final long value) { - if (value == 0) { - return 1; + public static void main(String[] args) throws Throwable { + for (int i = 0; i < 10000; i++) { + int len1 = computeRawVarint32Size(encodeZigZag32(i)); + int len2 = computeSInt32SizeNoTag(i); + if (len1 != len2) { + throw new RuntimeException(" i = " + i + ", len1: " + len1 + ", len2: " + len2); + } } + } + + protected static int computeSInt64SizeNoTag(final long value) { + if (value == 0) return 1; return computeUInt64SizeNoTag(encodeZigZag64(value)); } protected static int computeUInt32SizeNoTag(final int value) { - if (value == 0) { - return 1; - } + if (value == 0) return 1; int clz = Integer.numberOfLeadingZeros(value); return ((Integer.SIZE * 9 + (1 << 6)) - (clz * 9)) >>> 6; } protected static int encodeZigZag32(final int n) { - if (n == 0) { - return 0; - } + if (n == 0) return 0; return (n << 1) ^ (n >> 31); } protected static long encodeZigZag64(final long n) { - if (n == 0) { - return 0L; - } + if (n == 0) return 0L; return (n << 1) ^ (n >> 63); } @@ -504,7 +514,8 @@ public class ProtobufFactory extends ConvertFactory data = readAtomicBooleans(LIS_CREATOR); + return data.toArray(new AtomicBoolean[data.size()]); + } + + public final Collection readAtomicBooleans(Creator creator) { + int size = readRawVarint32(); + Collection data = creator.create(); + for (int i = 0; i < size; i++) { + data.add(new AtomicBoolean(readBoolean())); + } + return data; + } + @Override public final byte readByte() { return (byte) readInt(); diff --git a/src/main/java/org/redkale/convert/pb/ProtobufWriter.java b/src/main/java/org/redkale/convert/pb/ProtobufWriter.java index 5c0ffb084..4c7dad07e 100644 --- a/src/main/java/org/redkale/convert/pb/ProtobufWriter.java +++ b/src/main/java/org/redkale/convert/pb/ProtobufWriter.java @@ -24,6 +24,7 @@ public class ProtobufWriter extends Writer implements ByteTuple { Integer.getInteger("redkale.convert.writer.buffer.defsize", 1024)); private static final int CHILD_SIZE = 8; + protected static final byte[] EMPTY_BYTES = new byte[0]; protected static final int TENTHOUSAND_MAX = 10001; @@ -401,7 +402,7 @@ public class ProtobufWriter extends Writer implements ByteTuple { if (array != null && array.length > 0) { for (String item : array) { writeTag(tag); - byte[] bs = item == null ? new byte[0] : item.getBytes(StandardCharsets.UTF_8); + byte[] bs = item == null ? EMPTY_BYTES : item.getBytes(StandardCharsets.UTF_8); writeBytes(bs); } } @@ -412,7 +413,7 @@ public class ProtobufWriter extends Writer implements ByteTuple { if (array != null && !array.isEmpty()) { for (String item : array) { writeTag(tag); - byte[] bs = item == null ? new byte[0] : item.getBytes(StandardCharsets.UTF_8); + byte[] bs = item == null ? EMPTY_BYTES : item.getBytes(StandardCharsets.UTF_8); writeBytes(bs); } } @@ -758,6 +759,32 @@ public class ProtobufWriter extends Writer implements ByteTuple { } } + public final void writeAtomicBooleans(AtomicBoolean[] value) { + AtomicBoolean[] array = value; + if (array != null && array.length > 0) { + writeLength(array.length); + for (AtomicBoolean item : array) { + writeTo(item != null && item.get() ? (byte) 1 : (byte) 0); + } + } + } + + public final void writeAtomicBooleans(Collection value) { + Collection array = value; + if (array != null && !array.isEmpty()) { + writeLength(array.size()); + for (AtomicBoolean item : array) { + writeTo(item != null && item.get() ? (byte) 1 : (byte) 0); + } + } + } + + public final void writeAtomicBooleans(Stream value) { + if (value != null) { + writeAtomicBooleans(value.toArray(s -> new AtomicBoolean[s])); + } + } + public final void writeAtomicIntegers(AtomicInteger[] value) { AtomicInteger[] array = value; if (array != null && array.length > 0) { @@ -961,6 +988,14 @@ public class ProtobufWriter extends Writer implements ByteTuple { } } + @ClassDepends + public final void writeFieldValue(int tag, AtomicBoolean value) { + if (value != null && value.get()) { + writeTag(tag); + writeBoolean(value.get()); + } + } + @ClassDepends public final void writeFieldValue(int tag, AtomicInteger value) { if (value != null && value.get() != 0) { @@ -1105,6 +1140,14 @@ public class ProtobufWriter extends Writer implements ByteTuple { } } + @ClassDepends + public final void writeFieldValue(int tag, AtomicBoolean[] value) { + if (value != null && value.length > 0) { + writeTag(tag); + writeAtomicBooleans(value); + } + } + @ClassDepends public final void writeFieldValue(int tag, AtomicInteger[] value) { if (value != null && value.length > 0) { @@ -1192,6 +1235,14 @@ public class ProtobufWriter extends Writer implements ByteTuple { } } + @ClassDepends + public final void writeFieldAtomicBooleansValue(int tag, Collection value) { + if (value != null && !value.isEmpty()) { + writeTag(tag); + writeAtomicBooleans(value); + } + } + @ClassDepends public final void writeFieldAtomicIntegersValue(int tag, Collection value) { if (value != null && !value.isEmpty()) { diff --git a/src/test/java/org/redkale/test/convert/GenericEntityTest.java b/src/test/java/org/redkale/test/convert/GenericEntityTest.java index c9d1bafc6..fee64926f 100644 --- a/src/test/java/org/redkale/test/convert/GenericEntityTest.java +++ b/src/test/java/org/redkale/test/convert/GenericEntityTest.java @@ -11,6 +11,8 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; import java.util.function.Supplier; import org.junit.jupiter.api.*; import org.redkale.convert.ConvertColumn; @@ -27,7 +29,7 @@ import org.redkale.util.Utility; public class GenericEntityTest { private static final Type ENTITY_TYPE = new TypeToken>() {}.getType(); private static final String JSON = - "{\"oneEntry\":{\"key\":\"aaaa\",\"value\":{\"addr\":\"127.0.0.1:6666\",\"addrs\":[22222,33333,44444,55555,66666,77777,88888,99999],\"desc\":\"\",\"id\":1000000001,\"lists\":[\"aaaa\",\"bbbb\",\"cccc\"],\"map\":{\"AAA\":111,\"CCC\":333,\"BBB\":222},\"name\":\"this is name\\n \\\"test\",\"strings\":[\"zzz\",\"yyy\",\"xxx\"]}},\"oneList\":[1234567890],\"oneName\":\"你好\"}"; + "{\"oneEntry\":{\"key\":\"aaaa\",\"value\":{\"addr\":\"127.0.0.1:6666\",\"addrs\":[22222,-33333,44444,-55555,66666,-77777,88888,-99999],\"desc\":\"\",\"id\":1000000001,\"lists\":[\"aaaa\",\"bbbb\",\"cccc\"],\"map\":{\"AAA\":111,\"CCC\":333,\"BBB\":-222},\"name\":\"this is name\\n \\\"test\",\"strings\":[\"zzz\",\"yyy\",\"xxx\"]}},\"oneList\":[1234567890],\"oneName\":\"你好\",\"oneStatus\":[true,false],\"oneTimes\":[128]}"; public static void main(String[] args) throws Throwable { GenericEntityTest test = new GenericEntityTest(); @@ -175,6 +177,10 @@ public class GenericEntityTest { List list = new ArrayList<>(); list.add(1234567890L); bean.setOneList(list); + bean.setOneStatus(new AtomicBoolean[] {new AtomicBoolean(true), new AtomicBoolean(false)}); + List times = new ArrayList<>(); + times.add(new AtomicLong(128L)); + bean.setOneTimes(times); bean.setOneEntry(new Entry<>("aaaa", SimpleEntity.create())); return bean; } @@ -190,6 +196,12 @@ public class GenericEntityTest { @ConvertColumn(index = 3) private K oneName; + @ConvertColumn(index = 4) + private AtomicBoolean[] oneStatus; + + @ConvertColumn(index = 5) + private List oneTimes; + @Override public String toString() { return JsonConvert.root().convertTo(this); @@ -218,6 +230,22 @@ public class GenericEntityTest { public void setOneName(K oneName) { this.oneName = oneName; } + + public AtomicBoolean[] getOneStatus() { + return oneStatus; + } + + public void setOneStatus(AtomicBoolean[] oneStatus) { + this.oneStatus = oneStatus; + } + + public List getOneTimes() { + return oneTimes; + } + + public void setOneTimes(List oneTimes) { + this.oneTimes = oneTimes; + } } public static class Entry { diff --git a/src/test/java/org/redkale/test/convert/SimpleEntity.java b/src/test/java/org/redkale/test/convert/SimpleEntity.java index b456e9258..25ba5e65d 100644 --- a/src/test/java/org/redkale/test/convert/SimpleEntity.java +++ b/src/test/java/org/redkale/test/convert/SimpleEntity.java @@ -41,7 +41,7 @@ public class SimpleEntity { SimpleEntity v = new SimpleEntity(); v.setName("this is name\n \"test"); v.setId(1000000001); - v.setAddrs(new int[] {22222, 33333, 44444, 55555, 66666, 77777, 88888, 99999}); + v.setAddrs(new int[] {22222, -33333, 44444, -55555, 66666, -77777, 88888, -99999}); v.setStrings(new String[] {"zzz", "yyy", "xxx"}); List list = new ArrayList<>(); list.add("aaaa"); @@ -50,7 +50,7 @@ public class SimpleEntity { v.setLists(list); Map map = new HashMap<>(); map.put("AAA", 111); - map.put("BBB", 222); + map.put("BBB", -222); map.put("CCC", 333); v.setMap(map); v.setAddr(new InetSocketAddress("127.0.0.1", 6666));