[rules-users] Drools Number to String Coercion Issue

Wolfgang Laun wolfgang.laun at gmail.com
Tue Jun 19 12:49:38 EDT 2012


Assuming
public class MapTest {
    private Map<String,String> fields;
    public Map<String,String> getFields(){
        return fields;
    }
}

we can write these rules

rule "test String - string"
when
    MapTest( fields["String"] != null, fields["String"] == "10" )
then
    System.out.println( "String - string" );
end

rule "test String - int"
when
    MapTest( fields["String"] != null, fields["String"] == 10 )
then
    System.out.println( "String - int" );
end

rule "test Integer - string"
when
    MapTest( fields["Integer"] != null, fields["Integer"] == "20" )
then
    System.out.println( "Integer - string" );
end

rule "test Integer - int"
when
    MapTest( fields["Integer"] != null, fields["Integer"] == 20 )
then
    System.out.println( "Integer - int" );
end

and insert one fact:
        MapTest mapTest = new MapTest();
        mapTest.getFields().put( "String", new String( "10" ) );
        Map f = mapTest.getFields();
        f.put( "Integer", Integer.valueOf( 20 ) );
        kSession.insert( mapTest );

Using 5.4.0, you get
   Integer - int
   Integer - string
   String - int
   String - string
but with 5.3.0 it is
   Integer - int
   String - string

HTH
-W


More information about the rules-users mailing list