Global `@JsonInclude(Include.NON_NULL)` for all properties with a specific type
See original GitHub issueWhen trying to optionally skip the certain fields when serialising certain beans, I put them into Java-8 Optional<>
wrappers, as that’s what allows me to differentiate between omitted and explicit null
values on deserialisation.
As described in my respective Stackoverflow question and answer, I struggled to achieve this in a generic way via MixIns
, as the (default) JacksonAnnotationIntrospector
is ignoring them (at least for the @JsonInclude
annotation I was looking at).
My final workaround is far from ideal, but at least works for this one isolated use case.
Are MixIns
intentionally left out there or is it a bug?
Confirmed this under 2.7.4, 2.7.8, 2.8.5, and 2.8.6.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (18 by maintainers)
Top Results From Across the Web
Jackson: differing JsonInclude for all properties of certain type ...
This allows defaulting of all properties of given POJO easily, like: @JsonInclude(Include.NON_NULL) public class Stuff { public String name; ...
Read more >Jackson Tips: filtering with @JsonInclude | by @cowtowncoder
Include enum values: ALWAYS : Global default which means that nothing is filtered out (all values included) NON_NULL : All values except for ......
Read more >JsonInclude.Include (Jackson-annotations 2.7.0 API)
Value that indicates that only properties with null value, or what is considered empty, are not to be included. Definition of emptiness is...
Read more >Using @JsonInclude to define properties inclusion rules
@JsonInclude annotation can be used to indicate when the annotated property can be serialized. Normally property values are always included, ...
Read more >Jackson @JsonInclude Example - Java Guides
By default, Jackson does not ignore Null and Empty fields while writing JSON. We can configure Include.NON_NULL and Include.NON_EMPTY at property level as ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@CarstenWickner Yes, but with reproduction you can easily add
@JsonInclude
forNullableInteger
, and that behaves same as mix-in. So I am reasonably confident this is not related to mix-in handling but the fact that class-annotation (mix-in is simply a trick to make class annotation stick to a class without direct addition) is not used in such a setup for some reason.I did also observe that property-annotation does indeed work.
Included now for next 2.9.0 version: either 2.9.0.pr4, or, if no more pre-releases made, 2.9.0 itself.