Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "permessive" match strategy on include #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Grogdunn
Copy link

@Grogdunn Grogdunn commented Jun 9, 2017

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
    }
}

@Antibrumm
Copy link
Owner

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?

@Grogdunn
Copy link
Author

Grogdunn commented Jun 9, 2017

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.

@Antibrumm
Copy link
Owner

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 :)

@Grogdunn
Copy link
Author

I think it's a good idea... When I've some spare time I'll try to implement it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants