Filter method only got called once if the field is null when using `@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)`
See original GitHub issueDescribe the bug
The filter method only get called once if the field value is NULL
,
when using @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)
Version information 2.12.6.1
To Reproduce
- create an HTTP get endpoint to return an instance of
ObjectDto
which has aNULL
value forfieldDto
:
public class ObjectDto {
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)
private FieldDto fieldDto;
}
-
Send requests to the endpoint.
The first time, theequals()
method ofSomeFieldFilter
is called during the serialization. The same method never get called for the HTTP requests after. -
For instances that have a
non-NULL
value forfieldDto
, theequals()
method of SomeFieldFilter` gets called all the time during the serialization
Expected behavior
For instances that have a NULL
value for fieldDto
, the equals()
method of SomeFieldFilter
also gets called all the time during the serialization
Additional context N/A
Issue Analytics
- State:
- Created a year ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Jackson Tips: filtering with @JsonInclude | by @cowtowncoder
When serializing content as JSON (or another format Jackson supports), Jackson by default just writes out all property values as they are.
Read more >Ignore given custom value Jackson JSON - Stack Overflow
One more possible solution is to use custom filter where you could combine more than one requirement. Let's say we want to filter...
Read more >Applying Custom property inclusion rules using @JsonInclude ...
Include.CUSTOM and specify a filter class via @JsonInclude#valueFilter then the property value will only be serialized if it is not filtered ...
Read more >JsonInclude (Jackson-annotations 2.9.2 API) - javadoc.io
To exclude Map with only `null` value, you would use both annotations like so: ... of "Filter Object" to use in case content()...
Read more >JsonInclude.Include (Jackson-annotations 2.9.0 API)
Enumeration used with JsonInclude to define which properties of Java ... Value that indicates that only properties with non-null values are to be...
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
Thank you. I hope to have time to check the PR in near future – thank you for contributing it and sending CLA!
No worries, @cowtowncoder. Thanks a lot for checking it.
I replied on the PR #3486