Found one issue. When defining custom operation with upper case letters and then using it in a rule NullPointerException is thrown. When changing name to all lowercase it works ok. Here's sample kotlin code that triggers the issue:
jsonLogic.addOperation("Greet") { args -> "Hello, " + args[0] + "!" }
val result = jsonLogic.apply("""{"Greet": ["Sam"]}""", "{}") as String
assertEquals("Hello, Sam!", result)
Changing "Greet" to "greet" fixes the issue.
If that is intended behavior it would be nice to get custom exception with proper message (preferably when adding such operation).
Here's the stacktrace:
java.lang.NullPointerException
at io.github.jamsesso.jsonlogic.ast.JsonLogicParser.parse(JsonLogicParser.java:27)
at io.github.jamsesso.jsonlogic.ast.JsonLogicParser.parse(JsonLogicParser.java:71)
at io.github.jamsesso.jsonlogic.ast.JsonLogicParser.parse(JsonLogicParser.java:18)
at io.github.jamsesso.jsonlogic.JsonLogic.apply(JsonLogic.java:83)
at com.example.RulesTest.customOperationTest(RulesTest.kt:127)
...
Thanks for reporting @pn, I found a stray .toLowerCase that causes the issue. I've removed it and all other tests pass, so I'm assuming it's simply vestigial.
Hi!
Thank you for this useful library! :+1:
Found one issue. When defining custom operation with upper case letters and then using it in a rule NullPointerException is thrown. When changing name to all lowercase it works ok. Here's sample kotlin code that triggers the issue:
Changing
"Greet"
to"greet"
fixes the issue. If that is intended behavior it would be nice to get custom exception with proper message (preferably when adding such operation).Here's the stacktrace: