question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global `@JsonInclude(Include.NON_NULL)` for all properties with a specific type

See original GitHub issue

When 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:closed
  • Created 7 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Mar 11, 2017

@CarstenWickner Yes, but with reproduction you can easily add @JsonInclude for NullableInteger, 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.

0reactions
cowtowncodercommented, May 1, 2017

Included now for next 2.9.0 version: either 2.9.0.pr4, or, if no more pre-releases made, 2.9.0 itself.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found