Dynamically change/delete registered modules #5048
-
Is it possible to somehow operate object mapper's registered modules on a flight? I'm trying to dynamically add serialisers&deserialisers for a LocalDate, so multiple date formats can be supplied/sent via a service based on the locale. I intercept a http call and register a module with required date format serialiser&deserialiser but this leads to duplication and polluting Jackson registered modules, as it's being saved exactly how many requests I make. Not sure if there's a mechanism to optimally delete a module, or overwrite it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Short answer: No. And not really possible to do with the architecture. Longer answer differs a bit between current Jackson 2.x (no -- there's no way to remove modules) and 3.x (can remove during building; or rebuild()). But basically Modules make kinds of changes that cannot be dynamically modified once ObjectMapper is in use. So if you want to have different modules (or differently configured), you need separate mappers. |
Beta Was this translation helpful? Give feedback.
-
Also worth noting: you really cannot reliably add any new Modules after using an |
Beta Was this translation helpful? Give feedback.
Short answer: No. And not really possible to do with the architecture.
Longer answer differs a bit between current Jackson 2.x (no -- there's no way to remove modules) and 3.x (can remove during building; or rebuild()).
But basically Modules make kinds of changes that cannot be dynamically modified once ObjectMapper is in use.
So if you want to have different modules (or differently configured), you need separate mappers.