jsonata-java icon indicating copy to clipboard operation
jsonata-java copied to clipboard

custom function like math.random()

Open MaciejHadam opened this issue 1 year ago • 1 comments

In jsonata.js there is possibility to create binding to js namspace and then call a function. For example You can bind Math namespace and call round function.

$math().round(2.5)

How I can do the same binding in dashjoin jsonata implementation?

MaciejHadam avatar Feb 23 '24 07:02 MaciejHadam

The Java equivalent of this would be binding a class in com.dashjoin.jsonata.Jsonata.Frame.bind(String, JFunction) and then calling a method using reflection.

At the moment this is not possible and you have to register the methods individually as described here: https://github.com/dashjoin/jsonata-java?tab=readme-ov-file#custom-functions

$math.$round(44) $math binds to java.lang.Math and $round calls https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#round(double)

Thanks for raising this.

aeberhart avatar Feb 23 '24 09:02 aeberhart