Replies: 1 comment
-
|
Quick note: no, As to how to detect which mapper is being used, I'd probably consider use of "Attributes", which can be set for I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
Quick note: no, As to how to detect which mapper is being used, I'd probably consider use of "Attributes", which can be set for I hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
In my Spring Boot application, I maintain multiple
ObjectMapperinstances, for example:Inside some serializers/deserializers I need to determine which specific
ObjectMapperinstance is being used for the current serialization or deserialization.Previous behavior
In Jackson 2.x I could simply check:
JsonGenerator.getCodec()JsonParser.getCodec()This allowed me to compare the returned codec with my known
ObjectMapperinstances.Problem in Jackson 3
In Jackson 3,
getCodec()no longer works reliably, and I cannot determine which mapper initiated the serialization/deserialization.The only approach I’ve found is:
SerializationContextExt/DeserializationContextExt.JsonParser.objectReadContext()JsonGenerator.objectWriteContext()This works, but it feels fragile, overly complex, and likely to break in future versions.
Question
Is there a recommended or cleaner way in Jackson 3 to detect which
ObjectMapperinstance is being used inside a custom serializer or deserializer?Any suggestions or hints would be greatly appreciated.
Current solution (works but feels too hacky)
ObjectMapperTypemarkerCustom JsonMapper.Builder injecting the marker into the context
Utility methods
Summary
This approach works, but:
-it relies on Jackson SPI internals
-I’m not confident it will remain compatible in the future
I’m looking for a cleaner, officially supported way to achieve this, or confirmation that this is the correct approach in Jackson 3.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions