-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
全接口对象@Transient失效 #1903
Comments
能提供testcase么? |
public class Issues1903Test {
// Issues1903 issues =
public static void main(String[] args) {
MapHandler mh = new MapHandler();
mh.add("name", "test");
mh.add("age", 20);
Issues1903 issues = (Issues1903) Proxy.newProxyInstance(mh.getClass().getClassLoader(), new Class[]{Issues1903.class}, mh);
System.out.println(issues.getName());
System.out.println(issues.getAge());
System.out.println(JSON.toJSON(issues).toString()); //正确结果: {"age":20}
System.out.println(JSON.toJSONString(issues)); //正确结果: {"age":20}
}
}
interface Issues1903{
@Transient
public String getName();
public void setName(String name);
public Integer getAge();
public void setAge(Integer age);
}
class MapHandler implements InvocationHandler{
Map<String, Object> map = new HashMap<>();
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String name = method.getName().substring(3);
String first = String.valueOf(name.charAt(0));
name = name.replaceFirst(first, first.toLowerCase());
return map.get(name);
}
public void add(String key, Object val){
map.put(key, val);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
一个全接口对象, 通过代理生成的, 在接口中只声明了get, set方法, 没有字段申明.
在get上添加@transient, 会将这个字段序列出来.
原因是FieldInfo中强制判断了必须要有field才会判断是否是fieldTransient
fastjson/src/main/java/com/alibaba/fastjson/util/FieldInfo.java
The text was updated successfully, but these errors were encountered: