#72 JAXBBeanFactory cannot create bean for nested type

Dozer v5.1
closed-fixed
5
2009-06-30
2007-02-16
No

Hi,

When I'm mapping with JAXBBeanFactory, it works fine with mappings like this:
<field>
<a>field-a</a>
<b>Body.field-a</b>
</field>

But it fails with mappings like this:
<field>
<a>field-a</a>
<b>Body.Nested.field-a</b>
</field>

In the logging, I noticed that the factory incorrectly tries to create the bean (notice the misplaced $ in the method call):

Caused by: net.sf.dozer.util.mapping.MappingException: java.lang.NoSuchMethodException: ObjectFactory.createSelecterenSchadegevallenRequest10TypeBodyType$AlgemeneGegevensType()
at net.sf.dozer.util.mapping.factory.JAXBBeanFactory.createBean(JAXBBeanFactory.java:85)

As a workaround, I've solved this problem by doing an extra substitute action in the createBean method:

int indexOf = beanId.indexOf('$');
if (indexOf > 0) {
beanId = beanId.substring(0, indexOf) + beanId.substring(indexOf + 1);
if (log.isDebugEnabled()) {
log.debug("createBean(Object, Class, String) - HAS BEEN CHANGED TO ["+ beanId + "]");
}
}

Greetings,
Hans Beemsterboer

Discussion

  • Josh

    Josh - 2007-11-13

    Logged In: YES
    user_id=1315390
    Originator: NO

    I have noticed the same issue with inner classes in a slightly different scenario. If you use the JAXBBeanFactory when defining the mapping of the inner class of an inner class, you get the same error. For example, this mapping:

    <mapping wildcard="true">
    <class-a bean-factory="net.sf.dozer.util.mapping.factory.JAXBBeanFactory>example1.A$B$C</class-a>
    <class-b bean-factory="net.sf.dozer.util.mapping.factory.JAXBBeanFactory>example2.A$B$C</class-b>
    ...
    </mapping>

    you get an error that the following method could not be found:

    example2.ObjectFactory.createAB$C()

    In order to resolve both of these problems, you probably want to replace the logic that strips the dollar sign in the JAXBBeanFactory from a single "if" statement to a "while". That is, replace:

    int indexOf = beanId.indexOf('$');
    if (indexOf > 0) {
    beanId = beanId.substring(0, indexOf) + beanId.substring(indexOf + 1);
    if (log.isDebugEnabled()) {
    log.debug("createBean(Object, Class, String) - HAS BEEN CHANGED TO [" + beanId + "]");
    }
    }

    with

    int indexOf = beanId.indexOf('$');
    while (indexOf > 0) {
    beanId = beanId.substring(0, indexOf) + beanId.substring(indexOf + 1);
    indexOf = beanId.indexOf('$');
    if (log.isDebugEnabled()) {
    log.debug("createBean(Object, Class, String) - HAS BEEN CHANGED TO [" + beanId + "]");
    }
    }

    At least that's the idea. You could do a replaceAll() or something else along those lines as well.

    Hope that helps,
    Josh

     
  • Yashwant Joshi

    Yashwant Joshi - 2008-10-26

    Hi,

    We are facing the same problem while using mapper to populate objects from JAXB to java bean using JAXB bean factory. How can I resolve that. Please suggest.

     
  • dmitry (lv)

    dmitry (lv) - 2009-06-30
    • labels: --> Mapping Issue
    • milestone: --> Dozer v5.1
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed
     
  • dmitry (lv)

    dmitry (lv) - 2009-06-30

    Took a while, but anyway fixed.

     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks