Drools 6.1 - How to disable strict mode?

Short version: How to disable strict MVEL mode using the new KIE API?

I know that there is a configuration property "drools.dialect.mvel.strict" that can be set using the old KnowledgeBuilder API . However, I cannot find a way to do the same with the new API.

Long version: I have an object method called the Object attribute (String name), and the result can be many different types. Sometimes it can be a List, other String, or something else. Now, to use this method, I have to use a lot of castings or drool. In the following example:

$entity : RootEntity( attribute('authors') != null && attribute('authors').size() >= 3 && attribute('authors')[2] == 'whatever' ) 

I get errors like this:

 Unable to Analyse Expression attribute("authors").size() >= 3: [Error: unable to resolve method using strict-mode: java.lang.Object.size()] Unable to Analyse Expression attribute("authors")[2] == "whatever": [Error: unknown collection type: class java.lang.Object; property=] 

To make this work with strict customization, I need to enter the same expression:

 $entity : RootEntity( attribute('authors') != null && ((java.util.List) attribute('authors')).size() >= 3 && ((java.util.List) attribute('authors'))[2] == 'whatever' ) 

What can be disabled using strict settings.

+5
source share

Source: https://habr.com/ru/post/1204188/


All Articles