In Dozer's POM, org.apache.xmlbeans:xmlbeans is listed as an optional dependency.
However, attempting to use Dozer to handle a simple mapping in which Dozer needs to build the dest bean itself in a project that does not have xmlbeans as a dependency itself results in a NoClassDefFoundError.
Caused by: java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
The code that triggered this exception on my end looks something like:
final T obj = dao.get(id);
T copy = mapper.map(obj, clazz);
T is a type parameter for this method, clazz is defined as Class<T>
In effect this code simply retrieves an object instance from one of my DAOs and then passes it to Dozer to create a copy of itself (the reason for doing this is unrelated, but I am attempting to map the bean to a new instance to remove Hibernate proxies from the POJO instance).
From looking at the source code in Dozer 5.2.2 this error appears to occur because DestBeanMapper.create(BeanCreationDirective) polls each BeanCreationStrategy until it finds one that is applicable for the directive. The fourth entry in the availableStrategies array is ConstructionStrategies.XMLBeansBased, which attempts to use XmlBeans classes without checking to see if they are available. The BeanCreationStrategy which is ultimately used for my type, byConstructor, is last in the list.
Thus if DestBeanCreator needs to create the destBean with it's constructor, it will always first check if XmlBeans strategy is applicable - even if XmlBeans is not on the classpath.
I'd suggest either one of two changes: 1) remove optional=true for the xmlbeans dependency in the POM, or 2) add logic to ConstructionStrategies.XMLBeansBased to handle situations where the XmlObject class cannot be found (and return false instead of propogating any ClassDefNotFoundExceptions or NoClassDefFoundErrors).
Log in to post a comment.