Open Gems opened 2 months ago
I believe JsonInclude only applies to beans and maps.
Kind of: It does apply to Collection
s wrt "simple" empty case, but it does not filter elements. So only ones with Collection.isEmpty()
are filtered out, but not ones where there are elements that would be considered empty.
Yeah, I noticed it. But I don't think that it's expected behavior that comes to ones mind when then learn about the "non_empty" option.
I pathed the SerializerFactory
to make it to produce a CollectionSerializer
implented the same way the MapSerializer
is implemented. Works well.
I believe it could be a more straightforward behavior having empty collection/array items filtered out in case of the "non_empty" option is provided.
Changing this behavior would be major backwards-compatibility problem tho. And conceptually skipping is only for properties (of POJOs, Maps), not for elements (of Collections, arrays).
So while I understand why it's confusing, I don't think this is something I want to change.
No problem. I have my workaround implemented and it solves the problem we have.
Feel free to close the issue.
I'd suggest though leaving it open for comments, so I can share a relevant solution if anyone else has the same issue.
Cheers, Ed
Will leave open for bit, close in future -- closed issued should be googlable still.
Search before asking
Describe the bug
Empty Map values in collections don't get filtered out.
Version Information
2.17.2
Reproduction
Here is code for the corresponding unit test:
Expected behavior
It's expected that the test would pass.
Additional context
No response