Fix serialization of beans that are annotated with @JsonTypeInfo()#26
Merged
Conversation
We have currently a problem with polymorphic classes. They could not created by HALMapper in the correct HAL structure. Except the polymorphic class is in a other class embedded.
…ion (as.property)
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
============================================
+ Coverage 76.52% 76.83% +0.31%
- Complexity 62 63 +1
============================================
Files 10 10
Lines 345 354 +9
Branches 67 67
============================================
+ Hits 264 272 +8
- Misses 73 74 +1
Partials 8 8
Continue to review full report at Codecov.
|
Member
|
Awesome. Thanks a lot for the contribution. |
langecode
approved these changes
Jan 15, 2020
Member
|
Released in 1.0.6 |
Contributor
Author
|
Thanks for the release. We were glad to help. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR includes the prepared tests of #24 (he is my co-worker) and fixes the issue #25.
This PR solves two issues:
@JsonTypeInfo(...),jackson-databindwraps theHALBeanSerializerinto aTypeWrappedSerializerand serializes this instead. When calling the wrapped serializer, it uses theserializeWithType(...)method instead of theserialize(...)ofHALBeanSerializer. This function is not implemented by theHALBeanSerializerso the custom serialize function is not called. This is solved by implementing theserializeWithType(...)function that writes the type information and starts the custom HAL serializer.@JsonTypeInfo(...)is skipped in the current implementation. This is solved by not writing the embedded object directly, but by serializing it like all other properties withprop.serializeAsField(...). Since the name of the property might change due to a custom relation name in the@EmbeddedResource(name), the name needs to be replaced in the property to be serialized correctly.There is some more code in BeanSerializerBase#serializeWithType where I don't know if we need that in the overridden function and I didn't include that.
Closes #24 #25
PS: In case you like and merge this PR, we would be happy if you could also create a release soon so we can import it into our applications.