Java 模型的 JSON 字段映射
2022-09-02 09:57:47
发送的 JSON:
{
"Banner": "ABC"
}
Java模型:
...
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class BannerData implements java.io.Serializable {
private static final long serialVersionUID = 5664846645733319592L;
@JsonProperty(value = "Banner")
private String banner;
public String getBanner() {
return banner;
}
public void setBanner(String banner) {
this.banner = banner;
}
}
控制器:
@RequestMapping(value = {"/GetBanner"}, method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> enrollCustomer(@RequestBody BannerData body, HttpServletRequest request) throws Exception {
...
}
返回请求:
客户端发送的请求在语法上不正确。/GetBanner
当 json 更改为 (小写命名,如 Java 字段名称所示)时工作正常:
{
"banner": "ABC"
}
但是,我需要在JSON中命名大写字段。
看起来不起作用。@JsonProperty(value = "Banner")
映射是否正确?