You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
com.alibaba.fastjson.util.JavaBeanInfo类,如果父类存在泛型方法
public T getCode() {
return code;
}
public void setCode(T code) {
this.code = code;
}
子类存在方法
public int getCode() {
return code;
}
对于父类之类方法参数类型存在继承关系,然后add方法仅判断了 if (item.fieldClass.isAssignableFrom(field.fieldClass)),所以在getMethods得到的方法排序中,如果父类方法顺序在前,没有问题;如果父类方法顺序在后且int result = item.compareTo(field);结果小于0,后续序列化会使用父类方法,如果又恰好用到强制类型转化,反序列化会失败
static boolean add(List fieldList, FieldInfo field) {
for (int i = fieldList.size() - 1; i >= 0; --i) {
FieldInfo item = fieldList.get(i);
if (item.name.equals(field.name)) {
if (item.getOnly && !field.getOnly) {
continue;
}
if (item.fieldClass.isAssignableFrom(field.fieldClass)) {
fieldList.set(i, field);
return true;
}
int result = item.compareTo(field);
if (result < 0) {
fieldList.set(i, field);
return true;
} else {
return false;
}
}
}
fieldList.add(field);
return true;
}