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
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;
}
The text was updated successfully, but these errors were encountered:
使用版本 1.2.69版本,未发现解决公告
com.alibaba.fastjson.util.JavaBeanInfo类,如果父类存在泛型方法
public T getCode() {
return code;
}
public void setCode(T code) {
this.code = code;
}
子类存在方法
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
使用 clazz.getMethods()方法在不同环境得到的结果顺序可能不同;
对于父类之类方法参数类型存在继承关系,然后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);
The text was updated successfully, but these errors were encountered: