I am stuck with a problem which I have been trying to solve since last two days. I have an Integer
object and a Float
object which I do not want to display in the JSON
response if it is 0
. I am trying to achieve this with @JsonInclude(value=Include.NON_NULL)
but it doesn’t seem to be working.
Does anyone have any suggestion and can explain me what I am doing wrong here?
Lets say the model class is something like this:
@JsonInclude(value = Include.NON_NULL)
public class myClassInfo {
String originalQuery;
String normalizedQuery;
Long id;
Integer performanceStatus;
Float atcPercentage;
Integer ruleOn;
Integer ruleOff;
}
I have the getter and setter methods accordingly. I want to display the atcPercentage
, ruleOn
and ruleOff
only if it is not 0
. How would I do that? I hope this explanation helps in understanding my problem. I have tried NON_NULL
and it doesn't seems to be working. My understanding if I define the JsonInclude
in the beginning of the class, that should be applicable to all the fields. Correct me if I am wrong.