Add new JsonInclude.Include feature to exclude maps after exclusion removes all elements.
See original GitHub issueCurrent exclusion features NON_NULL and NON_EMPTY help greatly in removing unwanted text in the json payloads, but maps still get serialized if they originally contained an element even when that child element is removed because it is null or empty. For example, when making a json tree from this json:
{ "foo" : {"bar" : null } }
then serializing with NON_EMPTY produces this:
{"foo" : {} }
but ideally, I want the payload to be:
{}
Seems trivial in this case, but when dealing with a realistic payload like:
{"familyCount":{},"zipCode":{},"areaCode":["555"],"streetAddress":{},"profileInfo":{},"marketInfo":{},"longitude":{},"latitude":{}}
I would rather have to deal with just this:
{"areaCode":["512"]}
These payloads are transported to mobile devices, logged and written to databases, so having them compact and readable is highly desirable. I ended up having to write a “JSON cleaner” that recursively prunes empty nodes to get a compact and readable payload.
It would be great if the ObjectMapper had a built-in serialization feature like NON_EMPTY that does this.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top GitHub Comments
Thank you. Greatly appreciated.
On Thu, Nov 5, 2015 at 5:14 PM, Tatu Saloranta notifications@github.com wrote:
@kellerassel007 As per my other comment, while I do not doubt you have an issue, it is not necessarily the same underlying problem. And since this issue is closed, a new issue with reproduction is needed.