Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
GoogleCodeExporter opened this issue Jan 1, 2016 · 3 comments
Open

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

GoogleCodeExporter opened this issue Jan 1, 2016 · 3 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 16 Dec 2014 at 8:49

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 16 Dec 2014 at 8:52

@GoogleCodeExporter
Copy link
Author

Please can you add a unit test ?

Original comment by [email protected] on 20 Dec 2014 at 5:35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant