jackson-antpathfilter
jackson-antpathfilter copied to clipboard
Add a "permessive" match strategy on include
I've added a "permessive" match strategy with this you can:
- preserve the object structure when the filter a.b is specified (instead of specify filter for a and a.b)
- can extract from different children type a property with same name eg: *.id from:
{
"something": {
"id": 1,
"useless": "useless",
"...." : "...."
},
"something-else": {
"id": 1234,
"other-value" : "other value",
"...." : "...."
}
}
lead to:
{
"something": {
"id": 1
},
"something-else": {
"id": 1234
}
}
I think that this is already supported by the current implementation. You don't really need to change anything. Have you tried to use the pattern *.firstName
before your modifications?
Yes, if you pick the two new tests and put in current version this is the result:
Filter: *.firstName,
Result: {}
Because the matcher doesn't match the whole pattern
Filter: reports.firstName,
Result: {}
And because the filter does not contains '*' at first iteration no object keys is equals to the filter, then discard all the object.
Sorry for not answering earlier. Work is a bitch sometimes :)
I think this contribution is pretty nice. Just one request. Could you use the double-star pattern? **.firstName
This would be inline with the AntPath implementation.
I also have a doubt on how good this pattern will match for deeper nested models. As we don't know on the current level if there "will" be a firstName
finally we would have to scan the tree twice if I understand Jacksons serialization behavior.
Like user.firstname
, user.manager.firstname
and user.manager.manager.firstName
What do you think? I don't have yet an idea but if you have one shot :)
I think it's a good idea... When I've some spare time I'll try to implement it :+1: