猿问

@ResponseBody 将对象的所有值设置为 null。弹簧控制器

如果控制器使用 APPLICATION_XML_VALUE,则控制器工作正常,但无法与 APPLICATION_JSON_VALUE 一起使用。XML 请求正确填充所有字段,并且每个字段的 Json 版本都将为空。不确定我的 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"

  }

}


MMTTMM
浏览 213回答 1
1回答

胡子哥哥

我认为你的 JSON 应该是这样的{&nbsp; "number": "five",&nbsp; "music": "rock",&nbsp; "color": "RED"}
随时随地看视频慕课网APP

相关分类

Java
我要回答