This commit is contained in:
@@ -31,7 +31,7 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
|||||||
|
|
||||||
protected Creator<T> creator;
|
protected Creator<T> creator;
|
||||||
|
|
||||||
protected DeMember<R, T, ?>[] creatorConstructorMembers;
|
protected DeMember<R, T, ?>[] creatorConstructorMembers = new DeMember[0];
|
||||||
|
|
||||||
protected DeMember<R, T, ?>[] members;
|
protected DeMember<R, T, ?>[] members;
|
||||||
|
|
||||||
@@ -82,9 +82,10 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
|||||||
} else {
|
} else {
|
||||||
clazz = (Class) type;
|
clazz = (Class) type;
|
||||||
}
|
}
|
||||||
this.creator = factory.loadCreator(clazz);
|
if (!clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers())) {
|
||||||
if (this.creator == null) throw new ConvertException("Cannot create a creator for " + clazz);
|
this.creator = factory.loadCreator(clazz);
|
||||||
|
if (this.creator == null) throw new ConvertException("Cannot create a creator for " + clazz);
|
||||||
|
}
|
||||||
final Set<DeMember> list = new HashSet();
|
final Set<DeMember> list = new HashSet();
|
||||||
final String[] cps = ObjectEncoder.findConstructorProperties(this.creator);
|
final String[] cps = ObjectEncoder.findConstructorProperties(this.creator);
|
||||||
try {
|
try {
|
||||||
@@ -202,6 +203,13 @@ public final class ObjectDecoder<R extends Reader, T> implements Decodeable<R, T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.creator == null) {
|
||||||
|
synchronized (lock) {
|
||||||
|
if (this.creator == null) {
|
||||||
|
this.creator = factory.loadCreator(this.typeClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (this.creatorConstructorMembers == null) { //空构造函数
|
if (this.creatorConstructorMembers == null) { //空构造函数
|
||||||
final T result = this.creator.create();
|
final T result = this.creator.create();
|
||||||
while (in.hasNext()) {
|
while (in.hasNext()) {
|
||||||
|
|||||||
@@ -215,6 +215,7 @@ public final class ObjectEncoder<W extends Writer, T> implements Encodeable<W, T
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String[] findConstructorProperties(Creator creator) {
|
static String[] findConstructorProperties(Creator creator) {
|
||||||
|
if (creator == null) return null;
|
||||||
try {
|
try {
|
||||||
ConstructorParameters cps = creator.getClass().getMethod("create", Object[].class).getAnnotation(ConstructorParameters.class);
|
ConstructorParameters cps = creator.getClass().getMethod("create", Object[].class).getAnnotation(ConstructorParameters.class);
|
||||||
return cps == null ? null : cps.value();
|
return cps == null ? null : cps.value();
|
||||||
|
|||||||
Reference in New Issue
Block a user