I have the following beans:
1. JAXB - XMLApplication has a name, version and a list of XMLModules; XMLModule has a name and userName, where username uses a custom converter to convert between String and User
2. application beans (eventually these will be JPA entities) - Application that has a name, version and a list of Modules; Module has a name and a User
When the JAXB graph (#1) is unmarshalled, I try to create the other graph (#2). This works fine: the factories are called, the converter is called.
When I take the resulting Application instance, and try to map it back to XMLApplication, it doesn't work for the modules properties - the ones that get written to XMLApplication.modules are of type Module, simply reference-copied. The converter is not used, nor is the JAXBFactory - basically the whole mapping for XMLModule / Module is ignored.
I am attaching a test case (maven 2 project) that contains:
1. src/main/java/com.test.config - package for the Application hierarchy
2. src/main/java/com.test.dozer - package for the converter
3. src/main/generated/com.test.xml - package for the XMLApplication hierarchy, generated from my schema by JAXB plugin
4. src/main/resources/XML - application.xsd is the schema for JAXB, bindings.xjb refines the mapping slightly (influences the way code from #3 is generated) and dozerApplication.xml that is a Dozer mapping file
5. src/test/resources/XML/applicationInstance.xml - is a test XML file for JAXB to generate the graph
6. src/test/java contains one test class that unmarshalls the XML, performs the XMLApplication -> Application mapping, and then attempts to do it the other way round; is also contains a comment which point the error and the cause (ClassCastException)
The logs include the following line
test case
Sorry, wrong button clicked.
The logs include the following line:
Sep 15, 2010 12:23:55 PM org.dozer.MappingProcessor mapCollection
WARNING: The destination object: com.test.xml.XMLApplication@265a2eaa does not have a write method
I don't know what it refers to, the XMLApplication.modules field is configured to be directly accessible.
I am setting the priority to 9 as we are deciding whether to go with Dozer or not, and this will have influence on the decision.
Your test case works after providing collection mapping hint
<field>
<a is-accessible="true">modules</a>
<b>modules</b>
<b-hint>com.test.xml.XMLModule</b-hint>
</field>
However this is still a bug as Dozer looks at generic type on setter method only. Getter is ignored. And since JAXB generated Beans does not have setter for collections hint is needed as a workaround. Will be fixed in 5.3.1 and released this week. Hope it is not too late for you...
Dmitry
fixed. Will be released in 5.3.1