java如何使用JSONDOC将标题指定为application/json
我正在使用Spring4设计RESTAPI。但当我使用JsonDoc记录它时,它给了我一个错误:
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
Apache Tomcat/7.0.62
", "status": 415, "statusText": "Unsupported Media Type" }
@ApiMethod
@ApiHeaders(headers={ @ApiHeader(name="Content-Type", allowedvalues="application/json",description="application/json")})
@RequestMapping(value="/test" ,method=RequestMethod.POST)
public @ApiResponseObject @ResponseBody ResponseMessage test(@ApiBodyObject @RequestBody TestDto test){
System.out.println(test.getId());
return testService.addTestMessage("hello demo");
}
我如何测试它
# 1 楼答案
我相信这与JSONDoc无关。您需要检查发送的内容类型是否有效,比如application/json
还请检查TestDto JSON表示是否正确转换为JAVA对象。如果JSON字符串无法转换java对象,Spring会抛出此错误
# 2 楼答案
检查内容类型和有效负载格式
可能有一些属性不匹配