title: Drools 6.2 How to use ArrayList in declared types?
body: <p>Here is what I have in my DLR file:</p>
  
  <pre><code>package mytypes;
  
  declare Person
      firstName : String
      lastName : String    
      address : java.util.ArrayList
  end
  
  declare Address
      city : String
      state : String
  end
  
  rule "city"
  when 
   p : Person()
   Address(city == "Dallas") from p.address
  then
  System.out.println("city rule fired");
  end
  </code></pre>
  
  <p>I use gson to convert my json to ojbect of type Person using FactType. see below:</p>
  
  <pre><code>    FactType ft  = base.getFactType( "mytypes","Person" );
      Object oPerson = ft.newInstance();      
      Gson gConverter = new Gson();
      Object input = gConverter.fromJson(fact, oPerson.getClass());
  </code></pre>
  
  <p>Here is my json:</p>
  
  <pre><code>{"firstName":"John","lastName":"Smith","address":[{"city":"Dallas","state":"TX"}]}
  </code></pre>
  
  <p>I get the object back. This is how it looks in memory:</p>
  
  <pre><code>Person( firstName=John, lastName=Smith, address=[{city=Irving, state=TX}] )
  </code></pre>
  
  <p>My rule is not getting fired because as you can see there is no <strong>Address</strong> type inside <strong>address</strong> collection. Does anyone know how to make it work? </p>
  
  <p>Alternatively, if i don't use json to get the Person object and I build it manually using "getFactType" and set properties using "set" then I am able to get my rule fired. Here is how I build it manually</p>
  
  <pre><code>    FactType ftPerson  = base.getFactType( "mytypes","Person" );
      Object oPerson = ft.newInstance();
      ArrayList al = new ArrayList();
      FactType ftAddress  = base.getFactType( "mytypes","Address" );
      Object add = ftAddress.newInstance();
      ftAddress.set(add, "city", "Dallas");
      ftAddress.set(add, "state", "TX");
      al.add(add);
      ftPerson.set(oPerson, "address", al);
  </code></pre>
  
  <p>This is how Person object looks in memory and notice how <strong>Address</strong> type is specified in <strong>address</strong> collection:</p>
  
  <pre><code>Person( firstName=null, lastName=null, address=[Address( city=Irving, state=TX )] )
  </code></pre>
  
  <p>I hope i have explained the complete scenario. How can i still use json and still make it work?</p>