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.

Filter method only got called once if the field is null when using `@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)`

See original GitHub issue

Describe 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

  1. create an HTTP get endpoint to return an instance of ObjectDto which has a NULL value for fieldDto:
public class ObjectDto {

    @JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = SomeFieldFilter.class)
    private FieldDto fieldDto;

}
  1. Send requests to the endpoint.
    The first time, the equals() method of SomeFieldFilter is called during the serialization. The same method never get called for the HTTP requests after.

  2. For instances that have a non-NULL value for fieldDto, the equals() 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:open
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, May 24, 2022

Thank you. I hope to have time to check the PR in near future – thank you for contributing it and sending CLA!

0reactions
AmiDavidWcommented, Jun 13, 2022

No worries, @cowtowncoder. Thanks a lot for checking it.

I replied on the PR #3486

Read more comments on GitHub >

github_iconTop 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 >

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