I am working on an API in JAVA-Springboot. Below is a sample response from the API. I am querying the database for records and if no results are returned, I am sending a message "not found in database". There is an additional field on the same level, which is "loaded", which is also getting populated with the null value. Is there a way to add a condition that if message = "not found in database", don't even return loaded field? I only want to return loaded = null if the value for that field is null in the database.
{
"requestID":"45",
"requestDate""2021-10-16",
"details":{
"message":"not found in database",
"loaded":null
}
}
EDIT: I don't want to use @JsonInclude(Include.NON_NULL) because I want to return null if the database actually has null value for that field. But currently loaded is coming as null if I cannot even find an entry in database, which I want to solve.