<div dir="ltr">Hello,<div><br></div><div>I have a scenario where I have a rule that is searching for a particular object inside a list and the list is an entry in a hashmap.</div><div><br></div><div>An example of the class structure looks something like this.</div>
<div><br></div><div>class Player {</div><div> String name;</div><div>}</div><div><br></div><div>class TeamRoster {</div><div> // Maps team name to players</div><div> Map<String, List<Player>> teams;</div><div>
}</div><div><br></div><div>The goal of the rule is to activate when there is a player named John on the Dodgers team. I have tried writing rules a couple of ways but end up with errors using either approach. My first approach was the following:</div>
<div><br></div><div>dialect "mvel"</div><div>rule</div><div>when</div><div> $roster : TeamRoster()</div><div> $player : Player(name == "John") from $roster.teams["Dodgers"]</div><div>then</div>
<div> ...</div><div>end</div><div><br></div><div>However this resulted in the following error:</div><div><div>Unable to Analyse Expression $roster.teams["Dodgers"]:</div><div>sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class]</div>
</div><div><br></div><div>So I tried changing it up with the following...</div><div><br></div><div>dialect "mvel"<br></div><div>rule</div><div>when</div><div> $roster : TeamRoster()</div><div> $player : Player(name == "John")</div>
<div> eval($roster.teams["Dodgers"] contains $player</div><div>then</div><div> ...</div><div>end</div><div><br></div><div>This effectively yields the same error:</div><div><div>Expression $roster.teams["Dodgers"] contains $player:</div>
<div>sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class]</div></div><div><br></div><div>Note I am using Drools 6.0.1.Final. Is this some sort bug or limitation with the rules parser? Assuming I cannot change the class structure how can I achieve what I need?</div>
<div><br></div><div>Thanks in advance,</div><div><br></div><div>Jean-Philippe Steinmetz</div></div>