【发布时间】:2017-07-30 04:55:07
【问题描述】:
我的 Spring Boot 应用程序中有以下控制器:
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<ResponseDto<MyClass> process(@RequestBody RequestDto<MyClass> request){
return null;
}
MyClass 有一个字段,比方说“myField”,我想要不同的NamingStrategyconfiguration 用于该字段的请求和响应(这是因为我不想只为一个字段创建一个新类)。我已将ObjectMapper 实例配置如下:
@Bean
public ObjectMapper objectMapper(){
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(namingStrategy);
return objectMapper;
}
这将用于请求和响应(即反序列化和序列化),在 spring boot 中有什么方法可以指示控制器使用不同的ObjectMapper 实例?
【问题讨论】:
-
AFAIK 没有直接的方法。考虑实现你自己的
AbstractJackson2HttpMessageConverter
标签: java spring spring-boot jackson