Include.NON_DEFAULT doesn't work for value types, 2.7.0 and up
See original GitHub issuePlease 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:
- Created 6 years ago
- Comments:10 (5 by maintainers)
Top 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 >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
Oddly, Jackson >= 2.7.0 does behave properly if
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
is at the class level, rather than the property level.Since behavior change is now pretty old, new behavior is considered the default; closing this issue.