JsonPath 的 getPath 方法由于 PredicatePathToken 的 getPathFragment() 方法丢弃了谓词而无法完全反映路径
作者: jasonparallel创建于 2026年2月19日更新于 2026年2月19日
@Test void predicatePathTokenToStringTest() { final String expression = "$.store.book[?(@.title == 'Book A')].price"; JsonPath p = JsonPath.compile(expression); assertThat(p.getPath()).isEqualTo(expression); } Yields org.opentest4j.AssertionFailedError: expected: "$.store.book[?(@.title == 'Book A')].price" but was: "$['store']['book'][?]['price']" 由于 PredicatePathToken 的 getPathFragment() 方法只打印 [?]
内容来源: json-path/JsonPath