-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JsonCreator
on constructor not compatible with @JsonIdentityInfo
, PropertyGenerator
#2944
Comments
Thank you for reporting this: I hope to have a look at it soon. |
I can reproduce this; added failing test. Looks like CreatorProperty is somehow not linked to identity id -- so in the example case, field |
I spent some time looking into this. In BeanDeserializer._deserializeUsingPropertyBased (and probably various other related methods on other classes) it specifically excludes id properties from being added to the PropertyBuffer:
This looks very deliberate but I don't understand why it's necessary. The intention seems to be that id properties are handled at the end when the object is finally built. PropertyBasedCreator.build() calls through to buffer.handeIdValue which will attempt to set the id value using a setter if one is available as well as registering the object with the id resolver. Given that PropertyBasedCreator (AIUI) is only used for those cases where we're explicitly not using setters but instead passing the value to the creator method/constructor this seems like a mistake. Perhaps a copy/paste from some other creation code? If I get a chance I'll try just removing that |
@symposion Couple of notes. First, use of Second, I think (but am not 100% sure) that skipping of Object Id is due to most Object Ids being considered (identity) metadata, that is, something for which there is no matching property. The exception to this is the use of I think you are probably in thinking that skipping should not occur automatically. Somehow, the |
Ah. Missed the note on PR -- thank you, hope to check this either today or tomorrow! |
Yeah, it seems to work for my use case and none of the tests break... but Jackson is complicated and covers a lot of use cases so I'm not sure if there's some corner case that my fix would cause problems for. |
@JsonCreator
on constructor not compatible with @JsonIdentityInfo
, PropertyGenerator
On Jackson 2.11.3
A bean annotated with
@JsonIdentityInfo
pointing at an id property will not deserialize correctly using@JsonCreator
on its constructor. The code explicitly ignores identity fields when looking for constructor parameters (they are set after creation) but this makes JsonIdentityInfo incompatible with any sort of immutable object that requries all its properties to be set at construction time.I would expect this to print out "myId"; instead it prints "null". Note that you need to compile with -parameters for this to work
The text was updated successfully, but these errors were encountered: