#307 NullPointerException when mapping single fields to List

Dozer v5.3.2
closed-fixed
5
2015-01-20
2011-01-14
rakaposhi
No

I have following situation

public class Person1
{
private String familyName;
private String secondFamilyName;
}

public class PersonName
{
private String familyName;
}

public class Person2
{
private List<PersonName> personNames;
}

mapping:

<mapping>
<class-a>Person1</class-a>
<class-b>Person2</class-b>
<field>
<a>familyName</a>
<b>personNames[0].familyName</b>
</field>
<field>
<a>secondFamilyName</a>
<b>personNames[1].familyName</b>
</field>

when I execute the mapping I get a NullPointerException:

Stacktrace:

java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.dozer.factory.ConstructionStrategies$ByGetInstance.isApplicable(ConstructionStrategies.java:113)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:64)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:51)
at org.dozer.factory.DestBeanCreator.create(DestBeanCreator.java:47)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.writeDeepDestinationValue(GetterSetterPropertyDescriptor.java:195)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.setPropertyValue(GetterSetterPropertyDescriptor.java:86)
at org.dozer.fieldmap.FieldMap.writeDestValue(FieldMap.java:92)
at org.dozer.MappingProcessor.writeDestinationValue(MappingProcessor.java:869)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:331)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:270)
at org.dozer.MappingProcessor.map(MappingProcessor.java:239)
at org.dozer.MappingProcessor.map(MappingProcessor.java:181)
at org.dozer.MappingProcessor.map(MappingProcessor.java:125)
at org.dozer.MappingProcessor.map(MappingProcessor.java:120)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at com.cg.ihe.doc.sourceadapter.internal.TianiDozerMappingTest.testPatient(TianiDozerMappingTest.java:139)

I think the problem is in GetterSetterProperty in line 195 with pd.getPropertyType().getComponentType() because pd.getPropertyType() returns null for a java. util.List.

I think you should use Class<?> genericType = ReflectionUtils.determineGenericsType(pd); to determine the type as used in line 162.

Discussion

  • sah5

    sah5 - 2011-01-25

    I'm also getting this error, with Dozer v5.3.0.
    Any workaround in the meantime for this?

     
  • dmitry (lv)

    dmitry (lv) - 2011-02-12
    • assigned_to: nobody --> buzdin
    • status: open --> closed-fixed
     
  • dmitry (lv)

    dmitry (lv) - 2011-02-12

    fixed, will be in 5.3.2

     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks