-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[QUESTION]复杂的嵌套bean反序列化无法设置默认值 #367
Comments
你好, 默认值是有的, 但是构造函数里被覆盖为null, 在fastjson2中有两种解决方法
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class SubDTO2 {
private String id;
private String nickName;
private ThiDTO thiDTO = new ThiDTO();
private FouDTO fouDTO = new FouDTO();
}
@Data
@NoArgsConstructor
public class SubDTO {
private String id;
private String nickName;
private ThiDTO thiDTO = new ThiDTO();
private FouDTO fouDTO = new FouDTO();
} |
因为为SubDTO 非静态 内部类时, 创建SubDTO是通过构造是需要传入父TestDTO, 标记@AllArgsConstructor, fastjson2优先使用这个注解创建的构造参数, 那么在JSON文本中没有对应的 |
@kraity 感谢解答,目前已经可以达成期望结果。但是我们项目升级希望尽可能低的对原有代码做变更,请问之后会有计划在这方面做兼容或者优化吗? |
要支持还比较麻烦,我还要再想想 |
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.15-SNAPSHOT/ |
依赖版本
jdk1.8.0_162
DTO
json
运行代码
执行结果
其中SubDTO是TestDTO的成员内部类,ThiDTO与FouDTO与TestDTO同包类,这种嵌套类结构在使用1.2.x版本可以实现全部成员类的默认值。但是在2版本无法实现fouDTO的默认值。
请问除了将SubDTO从成员内部类提出来外还有别的方式可以实现默认值吗?
The text was updated successfully, but these errors were encountered: