You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(note, possible related to #885. Also note that this supercedes #558)
Choices used with @JsonInclude are currently somewhat limited, and specifically require either hard-coded criteria (null, or default property values of a POJO) or support from JsonSerializer for type (for "empty" check via `JsonSerializer.isEmpty(...)).
This makes it difficult to have custom criteria for exclusion without using other mechanisms like JSON Views or Json filter.
But it would seem possible to instead allow use of some kind of custom object that is called to determine whether given value is to be included/excluded.
While there are multiple possible ways to go about with this -- specifically, whether to create a new interface for comparing -- but one very simple way would be to simply use Object.equals(); method of comparator, and use return value to indicate inclusion (if true returned) vs exclusion (false).
The only other thing needed would seem to be to modify @JsonInclude so that:
There is a way specify the Class of custom comparator (default of Void.class to indicate "no custom comparator")
(optional) Add yet another JsonInclude.Include enum choice of CUSTOM
Of these, (2) is optional: we could choose to always check custom comparator, and if one defined, ignore enum. But from readability stand-point it seems better to add a new choice.
Also: for maximum power, we could choose to instead require implementation of some special interface, through which we could pass context (SerializerProvider). While this would be powerful, it seems that perhaps it is better not get carried away at this point: given that there are more powerful mechanisms for doing that (JSON Filter), we may want to keep this feature simple.