Menu

#366 ClassCastException when mapping List<List<String>>

Dozer v5.3.2
open
nobody
5
2016-05-24
2012-02-13
MartinN42
No

When trying to map a field with nested generic types like List<List<String>> I get a ClassCastException:

Exception in thread "main" java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
at org.dozer.util.ReflectionUtils.determineGenericsType(ReflectionUtils.java:364)
at org.dozer.util.ReflectionUtils.determineGenericsType(ReflectionUtils.java:352)
at org.dozer.propertydescriptor.GetterSetterPropertyDescriptor.genericType(GetterSetterPropertyDescriptor.java:335)
at org.dozer.fieldmap.FieldMap.getGenericType(FieldMap.java:145)
at org.dozer.MappingProcessor.mapCollection(MappingProcessor.java:493)
at org.dozer.MappingProcessor.mapOrRecurseObject(MappingProcessor.java:422)
at org.dozer.MappingProcessor.mapFromFieldMap(MappingProcessor.java:330)
at org.dozer.MappingProcessor.mapField(MappingProcessor.java:276)
at org.dozer.MappingProcessor.map(MappingProcessor.java:245)
at org.dozer.MappingProcessor.map(MappingProcessor.java:187)
at org.dozer.MappingProcessor.map(MappingProcessor.java:124)
at org.dozer.MappingProcessor.map(MappingProcessor.java:119)
at org.dozer.DozerBeanMapper.map(DozerBeanMapper.java:111)
at DozerTest.main(DozerTest.java:26)

See example in the attached Java file.

Discussion

  • MartinN42

    MartinN42 - 2012-02-13

    Example for ClassCastException when mapping nested generic types like List<List<String>>

     
  • MartinN42

    MartinN42 - 2012-02-13
    • summary: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl --> ClassCastException when mapping List<List<String>>
     
  • Jose Carlos

    Jose Carlos - 2016-05-23

    Hi Martin,

    It looks a quite old thread, but did you tried to specify a hint to the destination object a List?

    <b-hint>java.util.List</b-hint>

    Regards.

     
  • MartinN42

    MartinN42 - 2016-05-24

    Sorry, it's too long ago. I can't remember if and how I fixed the problem.

     

Log in to post a comment.