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

Union of missing properties returns empty object #984

Open
kluevi opened this issue Jan 17, 2024 · 0 comments
Open

Union of missing properties returns empty object #984

kluevi opened this issue Jan 17, 2024 · 0 comments

Comments

@kluevi
Copy link

kluevi commented Jan 17, 2024

Using a union of multiple properties, of which none exist, will return an empty object, or a list with a single empty object when using Option.ALWAYS_RETURN_LIST.

I would expect that, depending on configuration, either

  1. an empty list is returned, or
  2. an exception is thrown.

Tested with 2.7.0 and 2.8.0.

class Test {
    public static void main(String[] args) {
        String json = "{\"foo\":null}";

        Object o = JsonPath.read(json, "$['bar','baz']");
        // prints '{}'
        System.out.println(o);

        // throws Exception
        o = JsonPath.read(json, "$.bar");
        System.out.println(o);
    }
}
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

1 participant