[rules-users] Drools Number to String Coercion Issue

gqmulligan gqmulligan at gmail.com
Tue Jun 19 10:42:43 EDT 2012


Is there any way to let Drools handle a String, Number comparison without
having to manually do type conversions?

I am having trouble comparing a string to an integer in a rule. The rule can
be simplified to the following where fields is just a 

The problem is that given this rule, even when a = "10", the consequence is
never fired. According to the documentation at section 4.8.3.3.3 "Coercion
is always in favor of the field type and not the value type". So this rule
seems like the 10 should be coerced to "10" and then this comparison should
return true, but it doesn't.

If a change the 10 to "10" the rule succeeds. Also if I do
Integer.parseInt(fields["a"]) the rule succeeds.

The more interesting part is if I change the operator to > or < and change
the value of fields["a"] appropriately the rule still succeeds! Is this
because > and < aren't technically valid operators on Strings so the two
operands are converted to numeric values and compared?

I just noticed if I change the dialect to "java" then everything works as I
want. However, I still do not understand why it didn't work at first or if
it is safe to count on a different dialect to fix the issue.

--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Number-to-String-Coercion-Issue-tp4018067.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list