Tôi có lớp sau:@JsonCreator 'Không thể tìm thấy bất động sản với tên tác giả' ngay cả với ignoreUnknown = true
@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
}
}
}
Khi tôi cố gắng deserialize JSON, nó ném:
Không thể tìm thuộc tính người sáng tạo có tên 'nhận xét' (trong lớp com.test.domain.mapper.Topic)
Tôi không muốn điền comments
từ json, chỉ trong hàm tạo từ pr operties. Tuy nhiên, nếu tôi viết thông số tiếp theo:
@JsonProperty("success") boolean success,
@JsonProperty("response_comments") List<ResponseComment> responseComments,
@JsonProperty("response_users") List<ResponseUser> responseUsers,
@JsonProperty("comments") Object a,
@JsonProperty("users") Object a
tất cả các công trình.
Tạo [mcve] giúp chúng tôi. Giảm thiểu mã, ví dụ: xóa "response_comments" và "response_users". Cung cấp JSON dưới dạng văn bản. Sau đó, cung cấp mã sử dụng Jackson, lý tưởng như một bài kiểm tra đơn vị. Điều này sẽ khiến tôi bắt đầu quan tâm. Nếu tôi cần tìm ra điều đó, tôi chỉ nỗ lực quá nhiều. –
Tôi không thể sao chép, vui lòng hiển thị nội dung của đầu vào JSON –
Tôi chỉ có thể tạo lại nếu tôi thêm getter và setter cho các trường 'comments' và' users' –