Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix serialization of beans that are annotated with @JsonTypeInfo()#26

Merged
langecode merged 3 commits into
openapi-tools:masterfrom
dhenneke:feat/with-type-info
Jan 15, 2020
Merged

Fix serialization of beans that are annotated with @JsonTypeInfo()#26
langecode merged 3 commits into
openapi-tools:masterfrom
dhenneke:feat/with-type-info

Conversation

@dhenneke

Copy link
Copy Markdown
Contributor

This PR includes the prepared tests of #24 (he is my co-worker) and fixes the issue #25.

This PR solves two issues:

  1. When a class is annotated with @JsonTypeInfo(...), jackson-databind wraps the HALBeanSerializer into a TypeWrappedSerializer and serializes this instead. When calling the wrapped serializer, it uses the serializeWithType(...) method instead of the serialize(...) of HALBeanSerializer. This function is not implemented by the HALBeanSerializer so the custom serialize function is not called. This is solved by implementing the serializeWithType(...) function that writes the type information and starts the custom HAL serializer.
  2. The type information is not correctly included in embedded fields since the check for the @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 with prop.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.

Phil404 and others added 3 commits January 15, 2020 11:32
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.
@codecov

codecov Bot commented Jan 15, 2020

Copy link
Copy Markdown

Codecov Report

Merging #26 into master will increase coverage by 0.31%.
The diff coverage is 92.3%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
.../jackson/dataformat/hal/ser/HALBeanSerializer.java 84.49% <92.3%> (+0.32%) 4 <1> (+1) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c8e9fb...dd62364. Read the comment docs.

@langecode

Copy link
Copy Markdown
Member

Awesome. Thanks a lot for the contribution.

@langecode langecode merged commit 204fee3 into openapi-tools:master Jan 15, 2020
@langecode

Copy link
Copy Markdown
Member

Released in 1.0.6

@dhenneke dhenneke deleted the feat/with-type-info branch January 15, 2020 19:37
@dhenneke

Copy link
Copy Markdown
Contributor Author

Thanks for the release. We were glad to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants