Search before asking
Describe the bug
Consider this pattern where serialization to XML is customized for properties of collections ...
public class GroupDto {
@JacksonXmlElementWrapper(localName = "users")
@JacksonXmlProperty(localName = "user")
List<String> users;
// other fields
public GroupDto(List<String> users, /* other arguments */) {}
List<String> getUsers() { return users; }
// other getters
}
... such that the particular XML fragment looks like this:
<users>
<user>A</user>
<user>B</user>
<user>C</user>
</users>
<!-- other elements -->
This worked on Jackson 2.x, but fails on Jackson 3 with ...
InvalidDefinitionException: Invalid definition for property 'users' (of type `GroupDto`): Could not find creator property with name 'users' (known Creator properties: [user, /* other property names */])
Note the users/user difference in the message.
- Adding a
@JsonProperty to the field fails with an error about ambiguous property names instead.
- Changing the argument name in the constructor to the one seemingly expected (
user) does not help.
There appear to be two workarounds:
- Adding a no-arg constructor with
@JsonCreator (or removing all existing arg-constructors) and setters.
- Adding
@JsonIgnore to the field, and @JsonPropertys to the field's getters and setters.
Both workarounds are undesirable, as they make the class mutable and therefore prevent a migration to a record.
Version Information
Jackson 3.1.2
Reproduction
See code snippet above.
Expected behavior
There should be a way to deserialize types with fields that are annotated with @JacksonXmlElementWrapper and @JacksonXmlProperty, without making the class mutable (which prevents the use of records altogether).
Search before asking
Describe the bug
Consider this pattern where serialization to XML is customized for properties of collections ...
... such that the particular XML fragment looks like this:
This worked on Jackson 2.x, but fails on Jackson 3 with ...
Note the
users/userdifference in the message.@JsonPropertyto the field fails with an error about ambiguous property names instead.user) does not help.There appear to be two workarounds:
@JsonCreator(or removing all existing arg-constructors) and setters.@JsonIgnoreto the field, and@JsonPropertys to the field's getters and setters.Both workarounds are undesirable, as they make the class mutable and therefore prevent a migration to a record.
Version Information
Jackson 3.1.2
Reproduction
See code snippet above.
Expected behavior
There should be a way to deserialize types with fields that are annotated with
@JacksonXmlElementWrapperand@JacksonXmlProperty, without making the class mutable (which prevents the use of records altogether).