Feeco :
I have the following class:
@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
}
}
}
When I try to deserialize JSON, it throws:
Could not find creator property with name 'comments' (in class com.test.domain.mapper.Topic)
I don't want to fill comments
from json, just in constructor from properties. However, if I write next params:
@JsonProperty("success") boolean success,
@JsonProperty("response_comments") List<ResponseComment> responseComments,
@JsonProperty("response_users") List<ResponseUser> responseUsers,
@JsonProperty("comments") Object a,
@JsonProperty("users") Object a
all works.
Feeco :
After hours of unit testing and copying of classes, I found a solution. I don't want to admit it, but the issue in the Lombok's @AllArgsConstructor. I'm sorry that I didn't provided that I use Lombok at all.
Without @AllArgsConstructor
in Topic
all works as expected. However, it exists in other classes even with @JsonCreator
and works. I'm sorry for your time.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=452339&siteId=1