<p>XStream is a simple library to serialize objects to XML and back again.</p>
<p>Sometimes it can get tedious to call all those XStream 
aliases/register converter methods or you might simply like the new 
trend on configuring POJOs: Java annotations.</p>
<p>While using annotations if you ever got this exception the there might be a change that you forgot to call process annotation</p>
<pre>    XStream stream = new XStream(new DomDriver());
    stream.processAnnotations(YourClassName.class);</pre>
<p>Calling stream.processAnnotations(YourClassName.class); will clear down this exception.</p><br><br><div class="gmail_quote">On Tue, May 29, 2012 at 11:40 PM, Francois Rouaix <span dir="ltr">&lt;<a href="mailto:francois.rouaix@gmail.com" target="_blank">francois.rouaix@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">Folks,<div>I&#39;m trying to use Drools in a mostly Java-less environment (rules are written in .drl files, facts will be inserted from XML files). I&#39;m running into an issue where the XStream unmarshaller is unable to convert my XML to a BatchExecutionCommand because it cannot find the class for a type declared in the .drl file.</div>

<div>Is there any configuration required to make sure the XStream marshaller knows about the dynamically generated classes from the .drl?</div><div>I&#39;d appreciated any clues. I cannot add POJO classes for my types due to the nature of the app.</div>

<div>Thanks.</div><div><br></div><div><br></div><div>DRL file</div><div>-----------</div><div><div>package com.example</div><div>declare Answers </div></div><div>....</div><div>end</div><div>/* some rules after this */</div>

<div>...</div><div><br></div><div>XML file</div><div>-----------</div><div><div>&lt;batch-execution&gt;</div><div>  &lt;insert&gt;</div><div>   &lt;com.example.Answers&gt;</div></div><div>       ....</div><div><br></div>
<div>
<br></div><div>Runner code</div><div><div><span style="white-space:pre-wrap">        </span>public static void Run(String xmlFactsFile, String drlFilename)</div><div><span style="white-space:pre-wrap">        </span>{</div>
<div><span style="white-space:pre-wrap">                </span>// Compile the drl file</div><div><span style="white-space:pre-wrap">                </span>KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();</div>
<div><span style="white-space:pre-wrap">                </span>kbuilder.add( ResourceFactory.newFileResource(drlFilename),</div><div><span style="white-space:pre-wrap">                                </span>ResourceType.DRL );</div>
<div><span style="white-space:pre-wrap">                </span>if ( kbuilder.hasErrors() ) {</div><div><span style="white-space:pre-wrap">                        </span>System.err.println( kbuilder.getErrors().toString() );</div>
<div><span style="white-space:pre-wrap">                        </span>throw new RuntimeException(&quot;Cannot compile \&quot;&quot; + drlFilename + &quot;\&quot;&quot;);</div><div><span style="white-space:pre-wrap">                        </span>}</div>
<div><span style="white-space:pre-wrap">                </span></div><div><span style="white-space:pre-wrap">                </span>// kbase setup from the compiled rules</div><div><span style="white-space:pre-wrap">                </span>KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();</div>

<div><span style="white-space:pre-wrap">                </span>kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );</div><div><span style="white-space:pre-wrap">                </span></div><div><span style="white-space:pre-wrap">                </span>StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();</div>

<div><span style="white-space:pre-wrap">                </span>File facts = new File(xmlFactsFile);</div><div><span style="white-space:pre-wrap">                </span>BatchExecutionCommand command = (BatchExecutionCommand) BatchExecutionHelper.newXStreamMarshaller().fromXML(facts);</div>

<div><span style="white-space:pre-wrap">                </span>ExecutionResults bresults = ksession.execute(command);</div><div><span style="white-space:pre-wrap">                </span>System.out.println(BatchExecutionHelper.newXStreamMarshaller().toXML(bresults));</div>

<div><span style="white-space:pre-wrap">        </span>}</div><div>}</div></div><div><br></div><div>Error at runtime</div><div>----------------------</div><div><div>Exception in thread &quot;main&quot; com.thoughtworks.xstream.converters.ConversionException: com.example.Answers : com.example.Answers</div>

<div>---- Debugging information ----</div><div>message             : com.example.Answers</div><div>cause-exception     : com.thoughtworks.xstream.mapper.CannotResolveClassException</div><div>cause-message       : com.example.Answers</div>

<div>class               : org.drools.command.runtime.rule.InsertObjectCommand</div><div>required-type       : org.drools.command.runtime.rule.InsertObjectCommand</div><div>converter-type      : org.drools.runtime.help.impl.XStreamXML$InsertConverter</div>

<div>path                : /batch-execution/insert/com.example.Answers</div><div>line number         : 3</div><div>class[1]            : org.drools.command.runtime.BatchExecutionCommandImpl</div><div>converter-type[1]   : com.thoughtworks.xstream.converters.reflection.ReflectionConverter</div>

<div>version             : null</div><div>-------------------------------</div><div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)</div><div>        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)</div>

<div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)</div><div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)</div><div>

        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:318)</div><div>        at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:230)</div>

<div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)</div><div>        at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)</div>

<div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)</div><div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)</div><div>

        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)</div><div>        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)</div>

<div>        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1035)</div><div>        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1019)</div><div>        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:930)</div>

<div>        at com.intentsoft.RulesEngine.RulesExecution.Run(RulesExecution.java:34)</div><div>        at com.intentsoft.RulesEngine.Main.main(Main.java:10)</div><div>Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: com.example.Answers</div>

<div>        at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:55)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)</div><div>

        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:79)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:74)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div>

<div>        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30)</div><div>        at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:45)</div><div>        at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)</div>

<div>        at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:70)</div><div>        at org.drools.runtime.help.impl.XStreamXML$InsertConverter.unmarshal(XStreamXML.java:135)</div>

<div>        at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)</div><div>        ... 16 more</div></div><div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br>