j-easy / easy-rules

The simple, stupid rules engine for Java
https://github.com/j-easy/easy-rules/wiki
MIT License
4.83k stars 1.04k forks source link

Can I provide in clause in json like facts.get('value') in ('a', 'b', 'c', d') #414

Open naveenirukulapati opened 1 year ago

naveenirukulapati commented 1 year ago

Hi, I am doing a poc to use Easy rules by defining rules in a json file. My question is can I define in condition in json as provided below.

[ { "name": "TestRule", "description": "Test rule", "condition": "facts.get('value') in [9, 10]", "actions": ["System.out.println(\"Passed\");"] } ]

Currently I am getting an exception

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and java.lang.Boolean are in module java.base of loader 'bootstrap') at org.jeasy.rules.mvel.MVELCondition.evaluate(MVELCondition.java:65) at org.jeasy.rules.mvel.MVELRule.evaluate(MVELRule.java:120) at org.jeasy.rules.core.DefaultRulesEngine.doFire(DefaultRulesEngine.java:97) at org.jeasy.rules.core.DefaultRulesEngine.fire(DefaultRulesEngine.java:70) at com.wayfair.my.java.project.service.EasyRylesService.runEasyRulesEngine(EasyRylesService.java:53) at com.wayfair.my.java.project.service.EasyRylesService.main(EasyRylesService.java:31)

Thanks in advance for the help.

zhhaojie commented 9 months ago

That's because you provided illegal JSON data. It has nothing to do with easyRuleEngine. It doesn't need to care about how you store your rules.

[
    {
        "name": "TestRule",
        "description": "Test rule",
        "condition": "facts.get('value') in [9, 10]",
        "actions": [
            {
                "ACTION1": "DO ONE"
            },
            {
                "ACTION2": "DO TWO"
            }
        ]
    }
]