Frage

I have

public class CustomerA {

  private String street;

  public CustomerA() {
  }

  //get and set methods
}



public class CustomerB {

  private IAddress address;

  public CustomerB() {
  }

  //get and set methods
}

public class Address implements IAddress{

  private String street;

  public Address () {
  }

  //get and set methods
}

i want to map CustomerA to CustomerB using dozer

my mapping file

<mapping>
    <class-a>CustomerA</class-a>
    <class-b bean-factory="CustomerBBeanFactory">CustomerB</class-b>
    <field>
        <a>street</a>
        <b >address.street</b>
    </field>
</mapping>

In CustomerBBeanFactory i return a CustomerB object and set the address to new Address(). No use of factory means CustomerB cannot instantiate Address Class from interface.

But i am getting the below when i call the map method

java.lang.NullPointerException
at org.dozer.util.ReflectionUtils.invoke(ReflectionUtils.java:323)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.writeDeepDestinationValue(GetterSetterPropertyDescriptor.java:259)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.setPropertyValue(GetterSetterPropertyDescriptor.java:87)
at org.dozer.fieldmap.FieldMap.writeDestValue(FieldMap.java:94)
at org.dozer.MappingProcessor.writeDestinationValue(MappingProcessor.java:895)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:349)

Any ideas how this can be fixed ?

War es hilfreich?

Lösung

looks like the set-method did the trick

<mapping>
    <class-a>org.apache.camel.converter.dozer.service.Customer</class-a>
    <class-b bean-factory="org.apache.camel.converter.dozer.model.CustomerBeanFactory">org.apache.camel.converter.dozer.model.Customer
    </class-b>
    <field>
        <a>street</a>
        <b set-method="setStreet">address.street</b>
    </field>
</mapping>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top