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.

Include.NON_DEFAULT doesn't work for value types, 2.7.0 and up

See original GitHub issue

Please see the project at https://github.com/shawjef3/jackson-default-bug. It has a single test, which fails for Jackson 2.7.0 and higher, but succeeds for lower versions.

int i = 1;

@JsonProperty("i")
@JsonInclude(JsonInclude.Include.NON_DEFAULT) //doesn't work for jackson 2.7.0 and up
public int getI() {
    return i;
}

In the above an ObjectMapper will include “i” in the resulting json if i is 1, but not if i is 0. This behavior is reversed for versions below 2.7.0. I believe if the default is 1, as in the above code, it should not be included when the actual value is 1.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
shawjef3commented, Jun 15, 2017

Oddly, Jackson >= 2.7.0 does behave properly if @JsonInclude(JsonInclude.Include.NON_DEFAULT) is at the class level, rather than the property level.

0reactions
cowtowncodercommented, Apr 28, 2021

Since behavior change is now pretty old, new behavior is considered the default; closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson Included.NON_DEFAULT not working in 2.7.0
According to the bug ticket I put in for this, it is working as intended and that functionality can be achieved by structuring...
Read more >
Jackson JSON - @JsonInclude NON_DEFAULT Example
This is done by creating an instance of POJO using zero-argument constructor, and comparing the property values, excluding the ones having  ...
Read more >
Spring Security without the WebSecurityConfigurerAdapter
In Spring Security 5.4 we introduced the ability to configure HttpSecurity by creating a SecurityFilterChain bean. Below is an example ...
Read more >
CoffeeScript
The code compiles one-to-one into the equivalent JS, and there is no ... Functions may also have default values for arguments, which will...
Read more >
Compose file version 2 reference - Docker Documentation
Use the same values as the docker client --add-host parameter. ... no is the default restart policy, and it doesn't restart a container...
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