我们正在使用2.7.0版的springfox-swagger-ui和springfox-swagger2。
post 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
}
我的代码中没有对象永久地址。 该如何解决?
答案 0 :(得分:0)
在质疑为什么要使用permantnAddress之前,我认为更重要的是找出为什么地址是addressId,addressName和Address列表的对象。 JSON中看起来不正确。
Employee对象看起来像:
{
addresses: [
addressId: "string",
addressName: "string"
],
employeeName: "string",
employeeId: 0
}
permanentAddress是列表地址的正确对象