Skip to content

PredicateMatchEvaluator must create new context if left node is PathNode #356

@akugal

Description

@akugal

Consider next json is parsed into context variable:

{
  "store": {
    "book": [
      {
        "title": "Sayings of the Century",
        "price": {
          "value": 8.95,
          "currency": "usd"
        }
      },
      {
        "title": "Sword of Honour",
        "price": {
          "value": 12.99,
          "currency": "usd"
        }
      },
      {
        "title": "Moby Dick",
        "price": {
          "value": 8.99,
          "currency": "usd"
        }
      }
    ]
  }
}

and i want to fetch whole book nodes filtered by custom predicate on deep attributes like:

context.read("$..book[?]", Filter.filter(where("price.value").matches(new Predicate() {
            @Override
            public boolean apply(PredicateContext ctx) {
                // some custom logic with expecting value number in context
                return true;
            }
        })));

Here in context of predicate I expect NumberNode or unwrapped number but found book node.
After debugging I see that PredicateMatchEvaluator doesn't use left node. Shouldn't be there check if left node is PathNode then create new context based on parent context?

Please correct me if I'm wrong and provide way to do such filtering with custom predicate like I above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions