【发布时间】:2017-12-22 15:00:26
【问题描述】:
我有一个使用自定义 MIME 类型的 @RequestMapping。该请求使用@Configuration 中定义的ObjectMapper bean 来启用JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER。
此功能允许使用通常无效的 json(将反斜杠视为非特殊字符),这是此特定 @RequestMapping 的要求,以允许直接解析 google 编码的折线。然而,这意味着这个 ObjectMapper 现在被用于我的@RequestMapping 的所有,而实际上它只是一个要求。
有没有办法区分每个 @Controller 或 @RequestMapping 使用的 ObjectMapper?
对象映射器 Bean
@Bean
public ObjectMapper objectMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.featuresToEnable(
JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER);
return builder.build();
}
请求映射接口方法
@ApiOperation(value = "Returns the toll cost breakdown for a journey", notes = "", response = TotalCost.class, tags={ "pricing", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful operation", response = TotalCost.class) })
@RequestMapping(value = "/pricing/journeyCost",
produces = { "application/json" },
consumes = { "application/vnd.toll-pricing+json" },
method = RequestMethod.POST)
ResponseEntity<TotalCost> getTollBreakdownFromEncodedPoly(@ApiParam(value = "Request object representing the journey" ,required=true ) @RequestBody Journey body);
【问题讨论】:
-
您想要只对 Journey 界面进行自定义处理吗?
-
@lexknuther 基本上是的。
-
另外,您使用的是什么版本的 Jackson?
-
在这里您可以找到解决问题的可能方法 - stackoverflow.com/questions/42691392/…
-
@lexknuther 2.6.6
标签: java spring spring-boot jackson objectmapper