我们使用的是版本2.7.0的springfox-swagger-ui和springfox-swagger2。
后api具有以下签名:
@ApiOperation("Edits information about employees")
@PostMapping(path = "/employee/edit", headers = EndPoints.VERSION_1)
@ApiResponses(value = {
@ApiResponse(code = 409, message = "Data mismatch"),
@ApiResponse(code = 400, message = "Invalid data passed")
})
public ResponseEntity<Employee> manageEmployee(
@RequestHeader("employeeId") final String iEmployeeId,
@RequestBody(required = true) @Valid final Employee iEmployee)
对象员工是:
public class Employee implements Serializable {
private static final long serialVersionUID = -7315844547195801413L;
private String employeeName;
private Long employeeId;
private @Valid @NotNull List<Address> addresses;
// getter and setter methods
@Validated
public static class Address implements Serializable {
private static final long serialVersionUID = 6748945632164495934L;
private String addressId;
@ValidAddress
private String addressName;
//getter and setter methods
}
}
但招摇过程显示请求正文为:
{
"addresses": {
"addressId": "string",
"addressName": "string",
"permanentAddress": [
{
"addressId": "string",
"addressName": "string"
}
]
},
"employeeName": "string",
"employeeId": 0
}
对象permanentAddress不在我的代码中。怎么解决这个问题?
在质疑为什么permantnAddress之前,我认为找出为什么地址是addressId,addressName和Address列表的对象更为重要。在JSON中看起来不对劲。
Employee对象如下所示:
{
addresses: [
addressId: "string",
addressName: "string"
],
employeeName: "string",
employeeId: 0
}
permanentAddress是List地址的正确对象