Skip to content
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

ObjectFieldsAppendingMarker may use wrong unwrapping JsonSerializer when multiple ObjectMapper are used #642

Closed
brenuart opened this issue Sep 10, 2021 · 0 comments · Fixed by #643
Labels
Milestone

Comments

@brenuart
Copy link
Collaborator

The ObjectFieldsAppenderMarker maintains a cache of "unwrapping" JsonSerializer to use to serialise the object value and avoid creating for each invocation. When no suitable JsonSerializer can be found in the cache, a new one is created. This new instance is created from the ObjectMapper returned by the JsonGenerator given as argument to the current invocation. It is then added to the cache with the object's class as key.

A second attempt at serialising a value of the same class will therefore use a JsonSerializer obtained from the cache. However, there is no guarantee that the JsonGenerator passed as argument uses the same ObjectMapper as the one used when creating the JsonSerializer obtained from the cache.

brenuart added a commit that referenced this issue Sep 10, 2021
- Maintain a separate cache of JsonProvider per ObjectMapper
- do not create a new instance of SerializerProvider ourselves but instead use ObjectMapper#getSerializerProviderInstance introduced in Jackson 2.7
- do not create a JsonSerializer for the object class ourselves but instead delegate to Jackson SerializerProvider and therefore leverage its internal cache

Addresses issue #642
brenuart added a commit that referenced this issue Sep 10, 2021
- Maintain a separate cache of JsonProvider per ObjectMapper
- do not create a new instance of SerializerProvider ourselves but instead use ObjectMapper#getSerializerProviderInstance introduced in Jackson 2.7
- do not create a JsonSerializer for the object class ourselves but instead delegate to Jackson SerializerProvider and therefore leverage its internal cache

Addresses issue #642
brenuart added a commit that referenced this issue Sep 14, 2021
- Maintain a separate cache of JsonProvider per ObjectMapper
- do not create a new instance of SerializerProvider ourselves but instead use ObjectMapper#getSerializerProviderInstance introduced in Jackson 2.7
- do not create a JsonSerializer for the object class ourselves but instead delegate to Jackson SerializerProvider and therefore leverage its internal cache

Addresses issue #642
@brenuart brenuart linked a pull request Sep 14, 2021 that will close this issue
@philsttr philsttr added this to the 7.0 milestone Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants