我有以下课程:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Topic {
private List<Comment> comments = new ArrayList<>();
private List<User> users = new ArrayList<>();
@JsonCreator
public Topic(@JsonProperty("success") boolean success,
@JsonProperty("response_comments") List<ResponseComment> responseComments,
@JsonProperty("response_users") List<ResponseUser> responseUsers) {
if (success) {
comments = Util.resolveComments(responseComments);
users = Util.resolveUsers(responseUsers); //some logic
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试反序列化JSON时,它抛出:
找不到名为'comments'的创建者属性(在com.test.domain.mapper.Topic类中)
我不想comments从json 填充,只是在属性的构造函数中.但是,如果我写下一个参数:
@JsonProperty("success") boolean success,
@JsonProperty("response_comments") List<ResponseComment> responseComments,
@JsonProperty("response_users") List<ResponseUser> responseUsers,
@JsonProperty("comments") Object a,
@JsonProperty("users") Object a
Run Code Online (Sandbox Code Playgroud)
一切都有效.
Fee*_*eco 15
经过数小时的单元测试和复制课程,我找到了一个解决方案.我不想承认,但龙目岛的@AllArgsConstructor问题.对不起,我没有提供我完全使用龙目岛的事.
如果没有@AllArgsConstructor在Topic所有的作品如预期.但是,它存在于其他类中,即使是@JsonCreator有效的.我很抱歉你的时间.
| 归档时间: |
|
| 查看次数: |
5021 次 |
| 最近记录: |