-
-
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
Cannot merge polymorphic objects #2541
Comments
The workaround we ended up going with was writing a custom Deserializer that extends
|
Do we have any plan to support merging polymorphic objects? From my point of view, a polymorphic object which needs to be merged should not change its type, if this is the precondition then the merge process should be easy, just read the original object and set its fields. We have lots of polymorphic models in our project and heavily depend on this feature, it would be nice to support this in the new version. |
Yes, it often appears things are easy when you are not familiar with the details. This may be one of these cases. I'd be happy to help anyone who can implement it, but at this point do not have time to try to tackle the problem myself. |
Thanks for providing the detail information, I'll try if I can track the problem and send a pull request later. |
Good luck! |
Hi Tatu, I have added the merging polymorphic property logic in the code and tested, it works as expected now, the limitation is we can only merge the same sub type property, and I think it should be the case for most scenarios, changing the type of a polymorphic object doesn't make sense and it's not accepted by JPA as well, below is my implementation, please advice if there are any problems:
|
Any suggestions on the modification? Can I send a pull request for this? |
Would this actually work, for all kinds of polymorphic type embedding? Since this ignores You can definitely submit a PR, with tests to show expected working usage. I hope to have to look into it, although right now have bit of a time crunch. |
It only supports merging the same type polymorphic property, say if we have an old value which type is A, we can't change it to B in the merging process, like you said, changing the polymorphic type is very hard, and it usually doesn't make sense. I'll try to add unit tests to show the usage and submit a PR later, do you know who else can look at this? |
My concern is beyond different types -- yes, type cannot change, but more important, Type Id information should be incoming (json) content so who should handle that and how? If you submit PR, I can have a look & you can ask others on the mailing list. There are a few active collaborators but they mostly work on specific modules. |
Sorry for the late response, I have submitted a PR which includes the test cases, please review. |
Hi, Tatu, can you have a look at the pull request? |
Yes, I hope to look into this in near future. Right now I am severely overloaded unfortunately. Thank you for the PR! |
Apologies again for slow progress here: I am finally back to reviewing this. I realized that my concerns about cases where deserialization cannot succeed (and the nasty part of having to ignore unknown properties) can be easiest alleviated with just adding a new So: I think I will merge this in and do some post-processing. |
Will proceed once I get CLA, stay tuned! |
Referring to #2336 because there was a similar issue with polymorphic maps that was addressed there, and at the end of that issue it mentions:
We are on version
2.10.0
I have some classes defined similarly to:
The problem we're seeing is the incoming request completely overwrites the existing object instead of merging.
If we force a merge using
@JsonMerge
then an exception is thrown:Cannot merge polymorphic property 'thingy'
There are a few ways we're thinking of trying to get around this. One is to create a custom deserializer. And another is to manually merge the json via a deep node merge before passing to the reader similar to:
Can some type of deep node merge occur in Jackson for this polymorphic scenario to alleviate us having to maintain this json functionality ourselves?
The text was updated successfully, but these errors were encountered: