404-not-find / orika

Automatically exported from code.google.com/p/orika
2 stars 0 forks source link

Mapping List<String> to List<Enum> fails #185

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I can't find a place to submit issues on the GitHub page, so I'll have to do it 
here. I'm using 1.4.5.
I have a list of Enum Values (Strings) in one class and I want to map them to a 
list of Enums in another class.

What steps will reproduce the problem?
1. Create an enum called EnumTest, add "foo" and "bar" as enums.
2. Create a class called Class A, add List<String> enumTest as a property
3. Create an instance of Class A, add String values for "foo" and "bar" to 
enumTest.
4. Create a class called Class B, add List<EnumTest> enumTest as a property
5. Attempt to map an instance of Class A to Class B them with orika (without a 
custom converter):
mapperFactory.registerClassMap(mapperFactory.classMap(A.class, 
B.class).byDefault().toClassMap())

What is the expected output? What do you see instead?
I expect it to map without an issue. Instead, I get this error:
Error: java.lang.ClassCastException: EnumTest cannot be cast to java.lang.String
ma.glasnost.orika.MappingException: java.lang.ClassCastException: 
com.commercehub.eeprom.restservice.model.awareness.NotificationFrequency cannot 
be cast to java.lang.String
    at ma.glasnost.orika.impl.ExceptionUtility.newMappingException(ExceptionUtility.java:55) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:273) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.impl.MapperFacadeImpl.mapElement(MapperFacadeImpl.java:861) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.impl.MapperFacadeImpl.mapAsCollection(MapperFacadeImpl.java:686) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.impl.MapperFacadeImpl.mapAsSet(MapperFacadeImpl.java:425) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.generated.Orika_AwarenessConfiguration_AwarenessConfiguration_Mapper25487564015555$5.mapAtoB(Orika_AwarenessConfiguration_AwarenessConfiguration_Mapper25487564015555$5.java) ~[na:na]
    at ma.glasnost.orika.impl.mapping.strategy.UseCustomMapperStrategy.map(UseCustomMapperStrategy.java:67) ~[orika-core-1.4.5.jar:na]
    at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:263) ~[orika-core-1.4.5.jar:na]

What version of the product are you using? On what operating system?
1.4.5

Please provide any additional information below.

Original issue reported on code.google.com by hoste...@gmail.com on 16 Dec 2014 at 8:49

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Eh, well, I attempted to manually replace my classes with EnumTest in the error 
message. Didn't work out so well. I can provide further documentation if needed.

Original comment by hoste...@gmail.com on 16 Dec 2014 at 8:52

GoogleCodeExporter commented 8 years ago
Please can you add a unit test ?

Original comment by elaat...@gmail.com on 20 Dec 2014 at 5:35