【发布时间】:2018-12-09 12:42:39
【问题描述】:
我有一个带有布尔(不是原始布尔)属性的 bean。这是因为该属性与此类的每个实例都不相关,因此应该是nullable。
Bean 在创建 REST 服务上作为 JSON 发送。控制器接收到null,而不是实际值。
我的控制器:
@RestController
@RequestMapping("/myBean")
public class MyBeanController {
@Autowired
private MyBeanService myBeanService;
@PostMapping("/create" )
public ResponseEntity createTransaction(@RequestBody MyBeanDTO myBean) {
MyBeanDTO result = myBeanService.create(myBean);
return new ResponseEntity(result, HttpStatus.OK);
}
}
我的豆子:
public class MyBean {
. . .
private Boolean active;
. . .
public Boolean getActive() { //Instead of isActive, as it's Boolean and not boolean
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
}
我发送的所有 JSON 都没有正确解析“活动”属性,并且始终以 null 的形式出现。我试过 true,“true”,{“value”:true}。我错过了什么?
【问题讨论】:
标签: java json spring spring-boot boolean