Null fields aren't included on `JsonInclude.Include.ALWAYS`
See original GitHub issueI’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:
- Created 8 years ago
- Comments:9 (9 by maintainers)
Top 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 >
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 Free
Top 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

@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
AfterburnerModuleand 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
ObjectMapperused 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
ObjectMapperwithAfterburnerModule, it indeed was skipping the null fields, once I removed theAfterburnerModule, 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.Awesome job triaging the problem. Closing the issue because it’s kinda out of our hands