我有一個使用自定義MIME類型的@RequestMapping
。該請求使用在@Configuration
中定義的ObjectMapper
Bean來啓用JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER
。使用不同的傑克遜ObjectMappers進行單獨的RequestMapping
此功能允許消耗通常無效的json(將反斜槓當作非特殊字符),這是此特定@RequestMapping
的要求,以允許直接解析谷歌編碼多段線。然而這意味着這個ObjectMapper現在被用於我的@RequestMapping
的全部,當它真的只是一個需求的時候。
有沒有辦法區分每個@Controller
或@RequestMapping
使用的ObjectMapper?
對象映射豆
@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);
你想的只是自定義處理旅程界面? – 2017-07-18 00:13:24
@lexknuther本質上是的。 – Jags
另外,你使用的是什麼版本的傑克遜? – 2017-07-18 00:55:29