我在来自maven依赖库且具有私有构造函数的类上的控制器中使用@RequestBody批注。
@RequestMapping(value = "/myApi", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ApiOperation(value = "My API", response = CustomResponse.class, notes = "API response beautified")
public String apiOperation( @RequestBody @ApiParam(value = "ReqBody",required = true)
MyAPIBody apiReqBody ) {
// some code
// MyAPIBody is imported from maven dependency lib
// and has the all constructors as private
}
我收到415错误。
{
"timestamp": "2019-02-03T19:26:30.738+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/json;charset=UTF-8' not supported",
}
有人可以建议我做错了什么吗,或者我需要对项目结构进行一些更改。
我觉得它(带有私有构造函数的类)不应该与 requestbody 一起使用,因为当我将RequestBody参数应用于其他某个类时,它就可以了。但是,如果有人可以解释原因,那么我可以深思熟虑地更改项目结构。如果我的感觉不正确,请纠正我。