XML wrapper doesn't work with java records (original) (raw)

Using @JacksonXmlElementWrapper and @JacksonXmlProperty annotations with Java records results in deserialization exception.

For example, I'd expect following XML:

given text

to deserialize into following java records:

public record Request( @JacksonXmlElementWrapper(localName = "messages") @JacksonXmlProperty(localName = "message") List messages ) { public Request { }

private Request() {
    this(null);
}

}

public record Message(String text) { public Message { }

private  Message() {
    this(null);
}

}

However, it results in an exception:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Invalid definition for property 'messages' (of type `Request`): Could not find creator property with name 'messages' (known Creator properties: [message])
 at [Source: (StringReader); line: 1, column: 10]

This is unexpected because deserialization works with equivalent java classes.

This happens with Java 17 and Jackson version 2.13.2, which is the latest one as of this writing.

I've put together a minimal project which showcases the issue: jackson-record-showcase.