#105 Array mapping with XMLBeans throws NoSuchMehtod exception

closed
None
5
2014-08-11
2007-08-13
No

Hello,

I am trying to make use of dozer to map my domain objects to XmlBeans. I ran into an issue when dealing with collections...

In cases where I map properties on my domain object its XmlBeans array cousin, I get a java.lang.NoSuchMethodException. It seems as if Dozer is having a hard time finding constructors on my target?

My mappings are straightforward:

<mapping wildcard="false">
<class-a>ordering.core.domain.Order</class-a>
<class-b bean-factory="net.sf.dozer.util.mapping.factory.XMLBeanFactory">schemas.ordering.OrderDocument</class-b>
</mapping>

The field mapping that dozer blows up on is:
<field >
<a>orderLines</a>
<b>Order.LineItemArray</b>
<b-hint>schemas.ordering.LineItemType</b-hint>
</field>

Using a hint seems to have no effect. Is there something special that I need to do in order to get this to work properly with XmlBeans? I am not having much success with this and would like to avoid creating builders for all of my collection based properties if possible.

The stacktrace follows:

MapId: null
Type: bi-directional
Source parent class: ordering.core.domain.Order
Source field name: orderLines
Source field type: class java.util.HashSet
Source field value: [ordering.core.domain.OrderLine@20b4879]
Dest parent class: schemas.ordering.impl.OrderDocumentImpl
Dest field name: Order.LineItemArray
Dest field type: [Lschemas.ordering.LineItemType;
net.sf.dozer.util.mapping.MappingException: java.lang.NoSuchMethodException: <init>
at net.sf.dozer.util.mapping.util.MappingUtils.throwMappingException(MappingUtils.java:91)
at net.sf.dozer.util.mapping.util.DestBeanCreator.newInstance(DestBeanCreator.java:125)
at net.sf.dozer.util.mapping.util.DestBeanCreator.create(DestBeanCreator.java:83)
at net.sf.dozer.util.mapping.MappingProcessor.mapCustomObject(MappingProcessor.java:432)
at net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:404)
at net.sf.dozer.util.mapping.MappingProcessor.addOrUpdateToList(MappingProcessor.java:703)
at net.sf.dozer.util.mapping.MappingProcessor.mapListToArray(MappingProcessor.java:616)
at net.sf.dozer.util.mapping.MappingProcessor.mapSetToArray(MappingProcessor.java:729)
at net.sf.dozer.util.mapping.MappingProcessor.mapCollection(MappingProcessor.java:491)
at net.sf.dozer.util.mapping.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:395)
at net.sf.dozer.util.mapping.MappingProcessor.mapFromFieldMap(MappingProcessor.java:313)
at net.sf.dozer.util.mapping.MappingProcessor.mapField(MappingProcessor.java:274)
at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:216)
at net.sf.dozer.util.mapping.MappingProcessor.processSuperTypeMapping(MappingProcessor.java:886)
at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:206)
at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:132)
at net.sf.dozer.util.mapping.MappingProcessor.map(MappingProcessor.java:108)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
at net.sf.dozer.util.mapping.interceptor.StatisticsInterceptor.invoke(StatisticsInterceptor.java:44)
at $Proxy0.map(Ljava.lang.Object;Ljava.lang.Class;)Ljava.lang.Object;(Unknown Source)
at net.sf.dozer.util.mapping.DozerBeanMapper.map(DozerBeanMapper.java:93)
at ordering.webservice.util.OMSBeanMapperTest.testDomainToXmlBeans(OMSBeanMapperTest.java:37)
at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
Caused by: java.lang.NoSuchMethodException: <init>
at java.lang.Class.getDeclaredConstructor([Ljava.lang.Class;I)Ljava.lang.reflect.Constructor;(Unknown Source)
at net.sf.dozer.util.mapping.util.DestBeanCreator.newInstance(DestBeanCreator.java:121)
... 24 more

Discussion

  • Franz Garsombke

    Franz Garsombke - 2007-08-13

    Logged In: YES
    user_id=550744
    Originator: YES

    The root of the problem is this:

    After adding the bug I found out more...I will put this conversation on the bug.

    Basically, when we do nested mappings with XMLBean objects we don't use the bean factory defined at the class level...which is typically the XMLBeanFactory. XMLBeans has a custom way to create objects. So the top level objects are created fine...but any time we drill deeper we fail to use the XMLBeanFactory and just use the generic DestBeanCreator...which has no idea how to create XMLBeans.

    As soon as I define the field level classes as class mappings with the XMLBeanFactory as factory...it behaves correctly.

     
  • Franz Garsombke

    Franz Garsombke - 2007-09-16

    Logged In: YES
    user_id=550744
    Originator: YES

    Changing the destination bean creator was easy to use the XMLBeanFactory. There is a larger problem in the way XMLBeans deals with Arrays. When you define something as an Array in XMLBeans it creates a wrapper class and an interface. A concrete example would be ArrayOfWeatherDataImpl which implements ArrayOfWeatherData. Methods on this interface are things like:

    public net.sf.dozer.util.mapping.vo.WeatherData[] getWeatherDataArray()

    and

    public void setWeatherDataArray(net.sf.dozer.util.mapping.vo.WeatherData[] weatherDataArray)

    This creates a huge problem in how me map and determine collections. Our logic would never know that ArrayOfWeatherData is a way to wrap a collection. Even if it did there we would still have to get the actual array off of the wrapper class...manipulate it...and then put it back. Do you think this rabbit hole is worth going down?

     
  • Franz Garsombke

    Franz Garsombke - 2007-09-16

    Logged In: YES
    user_id=550744
    Originator: YES

    Disregard last comment. Looks like it is another issue.

     
  • Franz Garsombke

    Franz Garsombke - 2007-09-17
    • status: open --> pending
     
  • Franz Garsombke

    Franz Garsombke - 2007-09-17

    Logged In: YES
    user_id=550744
    Originator: YES

    Fixed on current_release branch. Look at the xmlBeansMapping.xml file for an example.

     
  • Franz Garsombke

    Franz Garsombke - 2007-09-27
    • status: pending --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks