Setting default value for boolean as true
This is the dto clas which is having boolean value in it.
DTO class
public class SensitivityDto extends AuditableEntity implements Serializable {
private static final long serialVersionUID = 1L;
private long sensitivityId;
@JsonIgnore
private boolean isSelected;
public SensitivityDto() {
}
/** other getter/setters */
public boolean isIsSelected() {
return isSelected;
}
public void setIsSelected(boolean isSelected) {
this.isSelected = isSelected;
}
}
input json
{
"sensitivity": {
"sensitivityId": 100,
"isSelected": "true", // if not passing this field always its treated as null.
}
}
Controller
public @ResponseBody ResultDecorator saveLabResultCultureDetails(@RequestBody SensitivityDto sensitivityDto) throws Exception {
}
How can I set boolean value default to true, So that if this value is not present in json, then it should not be false it should be true.