Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

没有public构造函数时,反序列化对象会报错default constructor not found #4394

Open
beanww opened this issue May 17, 2023 · 1 comment

Comments

@beanww
Copy link

beanww commented May 17, 2023

fastjson版本1.2.83
测试代码:
public class Test {
static class Obj {
private String s="1";
protected Obj(String a) {
s = "2";
}
}
public static void main(String[] args) {
String s = JSONObject.toJSONString(new Obj(null));
Obj o = JSONObject.parseObject(s, Obj.class);
System.out.println(s);
}
}

@beanww
Copy link
Author

beanww commented May 24, 2023

经验证,如果增加一个protected的无参构造,也可以解决此问题

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant