json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.95k stars 1.65k forks source link

Union of missing properties returns empty object #984

Open kluevi opened 10 months ago

kluevi commented 10 months ago

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