如果控制器消耗了APPLICATION_XML_VALUE,则控制器工作正常,但无法与APPLICATION_JSON_VALUE一起使用。 XML请求正确填充了所有字段,而Json版本的每个字段将为null。不确定我的json请求是否有问题?
@ApiOperation(value = "Update Thing")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = MembershipType.class), @ApiResponse(code = 503, message = " broke"),
@ApiResponse(code = 400, message = "error"), @ApiResponse(code = 500, message = "Internal server error") })
@RequestMapping(value = "/{id}/{id2}", method = RequestMethod.POST, consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<String> doThing(@PathVariable(value = "id") String id, @PathVariable(value = "id2") String id2, @RequestBody
MyObject myObjectRequest) {
return null;
}
工作XML请求
<myObjectRequest>
<number>five</number>
<music>rock</music>
<color>RED</color>
</myObjectRequest>
Json失败
{
"myObjectRequest": {
"number": "five",
"music": "rock",
"color": "RED"
}
}
答案 0 :(得分:1)
您认为JSON应该看起来像这样
{
"number": "five",
"music": "rock",
"color": "RED"
}