Details
-
Type:
Improvement
-
Status:
In Progress
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.9.2
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
When using @JsonUnwrapped annotation on a property, the filter is applied on the property itself, thus filtering everything.
Let's have a look at the following example :
{ "name" : "home", "latitude" : 127, "longitude" : 345 }to classes defined as:
@JsonFilter("myFilter")
class Place
@JsonFilter("myFilter")
class Location
If setting "myFilter" to return only "name" and "latitude", it returns only :
{ "name" : "home" }While I expect to have :
{ "name" : "home", "latitude" : 127, }This is due to the fact that "FilterExceptFilter.serializeAsField" method just checks for the name (but did not checked for the unwrap).
Changing one line of the method "FilterExceptFilter.serializeAsField" :
From
if (_propertiesToInclude.contains(writer.getName())) {
To
if (_propertiesToInclude.contains(writer.getName()) || writer instanceof UnwrappingBeanPropertyWriter) {
This works as expected
I have to think about whether this is considered a bug or feature. @JsonUnwrapped is all around nasty feature to support, leading to many potential issues with combinations...
So I can see your point, if the idea is that filtering would be occuring at JSON level, and not at POJO level. It comes down to which ordering of processing is assumed: does unwrapping occur first, before considering filtering, or after; and that determines which behavior is considered correct.