How do I add a Jackson mixin to a reader and not to the objectmapper?

前端 未结 2 800
时光说笑
时光说笑 2021-01-18 20:04

I have an object that I would like to serialize with an attribute in one part of my program, but without in a different part. I also have an ObjectMapper which is extensive

2条回答
  •  迷失自我
    2021-01-18 20:13

    Correct. You can not change mix-ins on-the-fly, however: since they are used for introspection of (de)serializers, and results (actual (de)serializers) are cached, they must be added as part of the initial configuration. This is why neither ObjectReader nor ObjectWriter exposes methods to change mix-ins: they only allow changing of things that can be dynamically changed, on per-call basis.

    But perhaps mix-ins are not the best way to do this: have you considered using JSON Views instead? Active view in use can be changed separately for each (de)serialization.

提交回复
热议问题