What version of OpenRewrite are you using?
Current main (4684213)
Minimal example
The following test in JsonPathMatcherTest:
@Test
void dollarToMatchTheRoot() {
assertMatched("$", simple, simple);
}
fails with:
line 1:1 mismatched input '<EOF>' expecting {'[', '.', '..'}
org.openrewrite.internal.RecipeRunException: java.lang.ClassCastException: class org.antlr.v4.runtime.tree.TerminalNodeImpl cannot be cast to class org.openrewrite.json.internal.grammar.JsonPathParser$ExpressionContext (org.antlr.v4.runtime.tree.TerminalNodeImpl and org.openrewrite.json.internal.grammar.JsonPathParser$ExpressionContext are in unnamed module of loader 'app')
at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:290)
[...]
Caused by: java.lang.ClassCastException: class org.antlr.v4.runtime.tree.TerminalNodeImpl cannot be cast to class org.openrewrite.json.internal.grammar.JsonPathParser$ExpressionContext (org.antlr.v4.runtime.tree.TerminalNodeImpl and org.openrewrite.json.internal.grammar.JsonPathParser$ExpressionContext are in unnamed module of loader 'app')
at org.openrewrite.json.JsonPathMatcher.find0(JsonPathMatcher.java:76)
at org.openrewrite.json.JsonPathMatcher.matches(JsonPathMatcher.java:86)
at org.openrewrite.json.JsonPathMatcherTest$2.visitLiteral(JsonPathMatcherTest.java:914)
at org.openrewrite.json.JsonPathMatcherTest$2.visitLiteral(JsonPathMatcherTest.java:864)
at org.openrewrite.json.tree.Json$Literal.acceptJson(Json.java:253)
at org.openrewrite.json.tree.Json.accept(Json.java:39)
at org.openrewrite.TreeVisitor.visit(TreeVisitor.java:250)
... 28 more
Broader context
- JsonPath is used as an argument to multiple recipes for languages like JSON or YAML
- AFAICT
$ is a valid JsonPath expression to denote the root of the document and it should be supported
- e.g.
|
spec -> spec.recipe(new AddKeyValue("$.", "key", "\"val\"", false)), |
uses $. (which BTW I think is invalid JsonPath), if you put $ there you get the same ClassCastException.
- in some contexts the exception is wrapped/handled and the only thing you can see is a warning:
line 1:2 mismatched input '<EOF>' expecting {'[', '*', Identifier, StringLiteral}
What version of OpenRewrite are you using?
Current main (4684213)
Minimal example
The following test in
JsonPathMatcherTest:fails with:
Broader context
$is a valid JsonPath expression to denote the root of the document and it should be supportedrewrite/rewrite-json/src/test/java/org/openrewrite/json/AddKeyValueTest.java
Line 30 in bf0519d
$.(which BTW I think is invalid JsonPath), if you put$there you get the sameClassCastException.