Open javster101 opened 2 years ago
What is the purpose of @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "name", scope = ProjectResource.class)
?
That definitely seems extra without other info.
Also, that @JsonSerialize
is unnecessary on class.
Maybe they were copied from some place without fully understanding semantics?
@javster101 Although ideally Records and similar POJOs would work same way, due to implementation challenges there are definitely cases where this is not true -- constraints that Records have did/do not exist for POJOs, and as such handling has been created initially for general POJOs and only later trying to make use of & support limitations Records have.
Also: 2.13.0 is old version so please try it out with 2.15.2 -- there have been many recent fixes to Record-type handling in 2.15 (as well as in 2.14).
BTW, I asked about the @JsonIdentityInfo
because:
One other final note: there's reference to XML, so issue may well be related to XML format module. And there have been TONS of fixes there since version 2.13.
Describe the bug When using @JsonIdentityInfo, Jackson deserializes an immutable class fine but the equivalent record does not.
Version information Jackson 2.13.0
To Reproduce I have a simple immutable class defined as follows:
The equivalent record is as follows:
The XML being deserialized is the following:
Finally, I have the following mapper (building with -parameters):
When I deserialize the XML to the first class it works fine, but when I do so to the second class I get the following error:
Can not set final java.lang.String field com.opengg.loader.Project$ProjectResource.name to java.lang.String
Maybe I'm doing something wrong, but my understanding of the record constructor syntax is that it generates the constructor in the same format as the immutable class, including any annotations. If the two classes are identical, I don't see a reason why the deserializer would be unable to use the constructor in the record case but have it work fine in the class case.
EDIT: This seems to be related to #3297.