在字段上应用@JsonProperty
之后,我在spring请求中同时获得了字段名和属性名。
public class RequestDto {
@JsonProperty("reference_id")
private String referenceId;
@JsonProperty("reference_type")
private String referenceType;
@JsonProperty("patient")
private Patient patient;
}
&
public class Patient {
@JsonProperty("birth_date")
private String birthDate;
@JsonProperty("first_name")
private String firstName;
@JsonProperty("last_name")
private String lastName;
}
spring swagger请求中的转换如下
{
"requestDto" : {
"referenceId" : "string",
"referenceType" : "string",
"patient": {
"birthDate": "string",
"birth_date": "string",
"firstName": "string",
"first_name": "string",
"lastName": "string",
"last_name": "string",
}
}
}