Skip to content

$match does not match function signature occurs when passing arguments without chaining #291

Description

@lo-jason

Sample code showing error
Running a simple code where a function is applied to the output of a $match expression

Expressions parse = Expressions.parse("$number($match($.a, /(\\d+)/).groups[0]))");
JsonNode inputNode = new ObjectMapper().readTree("{\"a\" : \"001\"}");

Results in an error from $match

com.api.jsonata4java.expressions.EvaluateException: Argument 1 of function $match does not match function signature
java.lang.RuntimeException: com.api.jsonata4java.expressions.EvaluateException: Argument 1 of function $match does not match function signature
	...
Caused by: com.api.jsonata4java.expressions.EvaluateRuntimeException: Argument 1 of function $match does not match function signature
	at app//com.api.jsonata4java.expressions.functions.MatchFunction.invoke(MatchFunction.java:99)
	at app//com.api.jsonata4java.expressions.ExpressionsVisitor.visitFunction_call(ExpressionsVisitor.java:1823)
	at 

Native Jsonata Works
The same input/output works just in Try Jsonata regardless of jsonata version
https://try.jsonata.org/y5CkUaJVY

Issue code
The inconsistency appears to be in FunctionUtils where the function is choosing to use the context despite it not being a valid input and having enough arguments already.

if (signature.indexOf("-") >= 0 && prc != null && prc instanceof PathContext) {
    return true;
}

Workaround
Swapping around the code so the string is actually used as the context will work
"$.a.$match(/(\\d+)/).groups[0] ~> $number()"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions