I have a Car class and a custom JsonInclude filter class IgnoreTrueFilter, the goal is to only serialize isNew property when its value is false:
public class Car {
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = IgnoreTrueFilter.class)
private boolean isNew = true;
}
public static class IgnoreTrueFilter {
@Override
public boolean equals(Object value) {
if (!(value instanceof Boolean)) {
return true;
}
return Boolean.TRUE.equals(value);
}
}
This works fine functionally, but Spotbugs is complaining:
$IgnoreTrueFilter.equals(Object) checks for operand being a Boolean EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS
It looks like Spotbugs is expecting the overriden equals method to check for a IgnoreTrueFilter instance instead of Boolean. But I'm just following JsonInclude.Include.CUSTOM's guidance:
* Filter object's equals() method is called with value
* to serialize; if it returns true value is excluded
* (that is, filtered out); if false value is included.
Any idea how to get around this error?