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.
Using lomback's @AllArgsConstructor and jackson 2.8.7. Upgrade jackson to 2.8.8 and problem resolved.
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.
After working on this for a few hours and confirming the behavior experienced by @Feeco, I was able to resolve this issue by upgrading Lombok from v1.16.16 to v1.16.20.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With