默认情况下,对布尔字段的 JSON 发布请求发送 false
2022-08-31 20:45:09
嗨,我正在使用FireFox RestClient发送JSON Post请求。
我的 JSON 请求如下所示:
{ "firstName": "Test", "lastName": "1", "isActive": 1 }
我的POJO有以下活动字段
private boolean isActive;
我的控制器定义如下
@RequestMapping(method = {RequestMethod.POST,
RequestMethod.PUT}, value = "/save")
public ResponseEntity<RestResponse> save(
@RequestBody POJOUserDetails userDetails, WebRequest request){
在我的POJO中,当我检查isActive的值时,无论我发送什么,它都是假的。我在 JSON 请求中尝试了低于值的值
"isActive": 1
"isActive": true
"isActive": "true"
"isActive": ""
"isActive": null
"isActive": false
以上所有内容都在我的控制器中发送 false。请帮忙。谢谢
添加 POJO 详细信息
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonSerialize(include=Inclusion.NON_EMPTY)
public class POJOUserDetails {
private String firstName;
private String lastName;
private boolean isActive;
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}