Can you configure Spring controller specific Jackson deserialization?

后端 未结 5 838
误落风尘
误落风尘 2020-12-15 16:42

I need to add a custom Jackson deserializer for java.lang.String to my Spring 4.1.x MVC application. However all answers (such as this) refer to configuring the ObjectMapper

5条回答
  •  旧巷少年郎
    2020-12-15 17:33

    You could try Message Converters. They have a context about http input request (for example, docs see here, JSON). How to customize you could see here. Idea that you could check HttpInputMessage with special URIs, which used in your controllers and convert string as you want. You could create special annotation for this, scan packages and do it automatically.

    Note

    Likely, you don't need implementation of ObjectMappers. You can use simple default ObjectMapper to parse String and then convert string as you wish. In that case you would create RequestBody once.

提交回复
热议问题