如果控制器使用了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>


失败的杰森

{
    "myObjectRequest": {
    "number": "five",
    "music": "rock",
    "color": "RED"
  }
}

最佳答案

我认为您的JSON应该看起来像这样

{
  "number": "five",
  "music": "rock",
  "color": "RED"
}

09-27 09:29