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

Allow wildcard path ignore #807

Open
Ragin-LundF opened this issue Aug 14, 2024 · 1 comment
Open

Allow wildcard path ignore #807

Ragin-LundF opened this issue Aug 14, 2024 · 1 comment

Comments

@Ragin-LundF
Copy link

Ragin-LundF commented Aug 14, 2024

We like to ignore a field, independent of its structural situation.
E.g.:

{
  "store": {
      "book": "HDR",
       "creationDate": "2020-12-12"
   }
}

or

{
  "creationDate": "2020-12-12",
  "store": {
      "book": "HDR"
   }
}

(just that simple).

When I look into the https://github.com/json-path/JsonPath/ library, they are using the pattern $..<fieldName>, so in our concrete case it should be $..creationDate.

Now I looked into the code and I would expect, that if I change the PathMatchers function matches() to this:

        @Override
        boolean matches(String pathToMatch) {
            return path.equals(pathToMatch)
                     || (path.startsWith("$..") && pathToMatch.endsWith(path.substring(2)))
                    || (path.startsWith("$.") && path.substring(2).equals(pathToMatch))
                    || (path.startsWith("$[") && path.substring(1).equals(pathToMatch));
        }

it should work.

Is it possible to implement this?


I found something strange here...

I have no idea how the Diff class works.
My test always fails and when I debug this project, it does some magical things.

When I call the method Diff.similar(), the property compared is false.
Now similar() calls compare(). Immediately after calling this method, the status of compared has been changed to true and the whole method is skipped.

If I set compared = true within this method to compared = false, the state does not change.

Maybe something is wrong with my debugger in IntelliJ, but I cannot pass the if (!compared) { section in the compare() method, the matcher is not executed properly, but the state changes and I can just avoid this by changing a part of the code, which is never executed....

So I would create a PR, but I'm unable to write a valid test for this change 😔.

@lukas-krecan
Copy link
Owner

Hi, thanks for reporting. Can you please shere the failing tests? I can somehow reconstruct from the description, but I want to be sure I understand.

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

No branches or pull requests

2 participants