I have an Object like this:
public class MyObject {
private String name;
private int number;
// ...
}
And I want to include the number
only if the value is not negative (number >= 0
).
While researching I found Jackson serialization: ignore empty values (or null) and Jackson serialization: Ignore uninitialised int. Both are using the @JsonInclude
annotation with either Include.NON_NULL
, Include.NON_EMPTY
or Include.NON_DEFAULT
, but none of them fits my problem.
Can I somehow use @JsonInclude
with my condition number >= 0
to include the value only if not negative? Or is there another solution how I can achieve that?