jamsesso / json-logic-java

A pure Java implementation of JsonLogic without using the Nashorn JS engine
MIT License
99 stars 50 forks source link

First argument to "SOME" must be a valid array #14

Closed rashhvarikuti closed 4 years ago

rashhvarikuti commented 4 years ago

@jamsesso I am using some in below rule to compare data:

here is the rule:

{ "and": [ { "some": [ { "var": "Fruits" }, { "if": [ { "==": [ { "var": "Fruit" }, "Apple" ] }, { "==": [ { "var": "Fruit" }, "Goa" ] } ] } ] }, { "some": [ { "var": "Veg" }, { "==": [ { "var": "Veg1" }, "Cali" ] } ] } ] }

while comparing I am getting below exception:

'io.github.jamsesso.jsonlogic.evaluator.JsonLogicEvaluationException: first argument to some must be a valid array at io.github.jamsesso.jsonlogic.evaluator.expressions.ArrayHasExpression.evaluate(ArrayHasExpression.java:35) at io.github.jamsesso.jsonlogic.evaluator.JsonLogicEvaluator.evaluate(JsonLogicEvaluator.java:132) at io.github.jamsesso.jsonlogic.evaluator.JsonLogicEvaluator.evaluate(JsonLogicEvaluator.java:22) at io.github.jamsesso.jsonlogic.evaluator.expressions.LogicExpression.evaluate(LogicExpression.java:35) at io.github.jamsesso.jsonlogic.evaluator.JsonLogicEvaluator.evaluate(JsonLogicEvaluator.java:132) at io.github.jamsesso.jsonlogic.evaluator.JsonLogicEvaluator.evaluate(JsonLogicEvaluator.java:22) at io.github.jamsesso.jsonlogic.JsonLogic.apply(JsonLogic.java:90)'

Could you please help out (SOME) is it bug? or Am I doing something wrong?

bvarghese1 commented 4 years ago

@jamsesso I am also seeing the same issue when the arraylike field is null. This evaluation works fine in http://jsonlogic.com/ Here is another example: JSONLogic: {"and":[{"some":[{"var":"ext"},{"in":[{"var":""},["docx"]]}]}]} Input Data: {"ext":null, "name":"TestDoc"}

bvarghese1 commented 4 years ago

@jamsesso Would it make sense to have an explicit null check before this https://github.com/jamsesso/json-logic-java/blob/master/src/main/java/io/github/jamsesso/jsonlogic/evaluator/expressions/ArrayHasExpression.java#L34 and remove the null check from isEligible? The null check can then return false.

jamsesso commented 4 years ago

@bvarghese1 That sounds like a reasonable solution to me 👍 are you comfortable making a PR?

bvarghese1 commented 4 years ago

@jamsesso Sure. I can give it a shot.

jamsesso commented 4 years ago

Thanks! That is a big help. Let me know if you need any help.

bvarghese1 commented 4 years ago

@jamsesso https://github.com/jamsesso/json-logic-java/pull/15 I was having issues with gradle. I had to update the descriptionUrl as follows:

-distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip

Let me know if you want me to update the distributionUrl as well.

jamsesso commented 4 years ago

Sure, that sounds good to me. I should spend some time getting this project up to date with the latest Gradle.