json
This commit is contained in:
@@ -374,7 +374,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
||||
DeMemberInfo info = this.memberInfo;
|
||||
if (this.creatorConstructorMembers == null) { // 空构造函数
|
||||
final T result = this.creator == null ? null : this.creator.create();
|
||||
do {
|
||||
while (in.hasNext()) {
|
||||
DeMember member = in.readField(info);
|
||||
in.readColon();
|
||||
if (member == null) {
|
||||
@@ -383,7 +383,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
||||
Object val = readDeMemberValue(in, member);
|
||||
member.getAttribute().set(result, val);
|
||||
}
|
||||
} while (in.hasNext());
|
||||
}
|
||||
in.readObjectE(typeClass);
|
||||
return result;
|
||||
} else { // 带参数的构造函数
|
||||
@@ -391,7 +391,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
||||
final Object[] constructorParams = new Object[constructorFields.length];
|
||||
final Object[][] otherParams = new Object[info.length()][2];
|
||||
int oc = 0;
|
||||
do { // in.hasNext()放在下面,因readObjectB已经读了{
|
||||
while (in.hasNext()) {
|
||||
DeMember member = in.readField(info);
|
||||
in.readColon();
|
||||
if (member == null) {
|
||||
@@ -410,7 +410,7 @@ public class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T> {
|
||||
otherParams[oc++] = new Object[] {member.attribute, val};
|
||||
}
|
||||
}
|
||||
} while (in.hasNext());
|
||||
}
|
||||
in.readObjectE(typeClass);
|
||||
if (this.creator == null) {
|
||||
return null;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
package org.redkale.test.convert.json;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.redkale.convert.Convert;
|
||||
@@ -42,10 +44,17 @@ public class Json5Test {
|
||||
System.out.println(bean2.name);
|
||||
Assertions.assertTrue(bean.equals(bean2));
|
||||
System.out.println(convert.convertTo(bean2));
|
||||
bean2 = convert.convertFrom(Json5Bean.class, new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)));
|
||||
System.out.println(bean2.name);
|
||||
Assertions.assertTrue(bean.equals(bean2));
|
||||
System.out.println(convert.convertTo(bean2));
|
||||
|
||||
String arrayJson = "[" + json + "," + json + "," + "]";
|
||||
Json5Bean[] beans = convert.convertFrom(Json5Bean[].class, arrayJson);
|
||||
System.out.println(convert.convertTo(beans));
|
||||
beans = convert.convertFrom(
|
||||
Json5Bean[].class, new ByteArrayInputStream(arrayJson.getBytes(StandardCharsets.UTF_8)));
|
||||
System.out.println(convert.convertTo(beans));
|
||||
|
||||
String intjson = "[1,2,3,4,]";
|
||||
int[] ints1 = convert.convertFrom(int[].class, intjson);
|
||||
|
||||
@@ -108,6 +108,9 @@ public class JsonMainTest {
|
||||
final JsonConvert convert = JsonConvert.root();
|
||||
long v = convert.convertFrom(long.class, "100");
|
||||
Assertions.assertEquals(100, v);
|
||||
Map<String, String> map = convert.convertFrom(JsonConvert.TYPE_MAP_STRING_STRING, "{}");
|
||||
Assertions.assertTrue(map.isEmpty());
|
||||
convert.convertFrom(SimpleChildEntity.class, "{}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user