Reputation: 1031
I'm using Jackson 2.4.3 and ObjectMapper
, which is configured to exclude empty properties (JsonInclude.Include.NON_EMPTY
), but I also using a custom PropertyFilter
during serialization and some of properties are excluded (not written) by this filter.
Exclusion of previously empty properties works fine, but if property value is skipped by my filter still appears in JSON.
At the end I have JSON file with empty properties which is highly unacceptable:
{"configurationPropertyList":{
"someProperty":{},
"someList":[{}, {}, {}]
}
}
Is there any way to get rid of those empty properties?
Let me also add, that finally JSON is quite big and complicated and for performance reason properly JSON should be produced by Jackson itself without any additional work. I'm trying to find as simple solution as possible.
Upvotes: 0
Views: 224
Reputation: 116472
The problem here is that filtering works on input Java Objects, and NOT on constructed JSON; which means that although much of contents of objects may be filtered (and result JSON Object is empty), object itself is not empty.
There is some on-going work (to be completed for 2.5) that may allow better handling, and possibly handle nested nature of filtering at least for java.util.Map
s. But right now, there is no automated solution for further trimming contents.
Upvotes: 2