I have a Spring Boot REST API and one of the endpoints takes requests that include a body, like this:
@GetMapping("/search")
public List<ItemDto> searchDevice(@RequestBody ItemDto itemDto){
// code
}
The DTO looks like this:
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ItemDto {
//other fields
@JsonProperty(value = "status")
private boolean status;
// getters and setters
}
So my problem is this: when I send a request not containing status it defaults to false, which is not the behaviour I need. I want status to be null, when it is not specified. How can I achieve this?
Another interesting behaviour is that status is false even when I specify it in the query as "status": null
As you can see, I already tried to use the annotations @JsonInclude and @JsonProperty, that I've seen recommended in similiar questions, but they are not working for me. The boolean still defaults to false. Is there any other fix for this?