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.

Null fields aren't included on `JsonInclude.Include.ALWAYS`

See original GitHub issue

I’m trying to force null fields to be written. When I tried it with a newly constructed object mapper, it works fine. But the object mapper used in the message body writer doesn’t write them out.

I’m configuring the ObjectMapper in the run method of my application subclass:

env.getObjectMapper().setSerializationInclusion(JsonInclude.Include.ALWAYS);

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
patroxcommented, Mar 30, 2016

@toadzky, @nickbabcock OK, looks like the url which I posted has been a dead-end, but I’ve been able to pinpoint what exactly is wrong in this scenario.

Seems like there is an interference between Jackson’s AfterburnerModule and Lombok (which is not so surprising, given the fact that both are messing with the Java bytecode).

I’ve found it out by looking up how the internal ObjectMapper used for Jackson in Dropwizard is configured:

https://github.com/dropwizard/dropwizard/blob/master/dropwizard-jackson/src/main/java/io/dropwizard/jackson/Jackson.java#L58

When I tried to serialize a Lombok annotated class using ObjectMapper with AfterburnerModule, it indeed was skipping the null fields, once I removed the AfterburnerModule, the null fields were included.

Besides, I’ve also found this past issue: https://github.com/dropwizard/dropwizard/issues/1111, describing how the set-up a customized ObjectMapper, in case if some of the pre-registered modules are not needed.

0reactions
nickbabcockcommented, Mar 30, 2016

Awesome job triaging the problem. Closing the issue because it’s kinda out of our hands

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson: Ignore empty fields except those that are mandatory ...
The idea to annotate specific fields with @JsonInclude (default value is ... Include.ALWAYS ) in field level to override the class level ...
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. NON_NULL. Value that indicates...
Read more >
Using @JsonInclude to define properties inclusion rules
Normally property values are always included, but by using this annotation we can specify simple exclusion rules based on property values. This ...
Read more >
Jackson @JsonInclude Example - Java Guides
The @JsonInclude annotation contains below two values: Include.NON_NULL: Indicates that only properties with not null values will be included in JSON.
Read more >
Jackson Tips: filtering with @JsonInclude | by @cowtowncoder
ALWAYS : Global default which means that nothing is filtered out (all values included) · NON_NULL : All values except for Java null...
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