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

User Guide code to map from List to Map throws ClassCastException #195

Open
GoogleCodeExporter opened this issue Jan 1, 2016 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?

1. Create three classes as described in User Guide:

public class Name {
    private String first;
    private String last;
    private String fullName;
    //getters & setters
}

public static class Person {
    private List<Name> names;
    //getters & setters
}

public static class PersonDto {
    private Map<String, Name> personalNames;
    //getters & setters
}


2. Create mapping and facade as described in user guide:

mapperFactory.classMap(Person.class, PersonDto.class)
        .field("names{fullName}", "personalNames{key}")
        .field("names{}", "personalNames{value}")
        .register();

MapperFacade mapper = mapperFactory.getMapperFacade();


3. Attempt to map Person to PersonDto (as per User Guide)

PersonDto personDto = mapper.map(person, PersonDto.class);


What is the expected output? What do you see instead?

Each Name in List<Name> should be mapped to Map<Name.fullName, Name>
Instead a ClassCastException occurs:
    "java.lang.ClassCastException: java.lang.Object cannot be cast to <package>.Name"

What version of the product are you using? On what operating system?
Tested on both Orika 1.4.2 (as per User Guide) and Orika 1.4.5 (latest)
Windows-7, 64bit

Please provide any additional information below.
Testcase attached
Duplicate of issue 166 - which has not been Accepted

Original issue reported on code.google.com by [email protected] on 30 Mar 2015 at 4:20

Attachments:

@GoogleCodeExporter
Copy link
Author

Code works if an explicit mapper is added for Name (see attached code)
        mapperFactory.classMap(Name.class, Name.class)
                .byDefault()
                .register();

I would have thought this would not be necessary, and don't understand why it 
is.
Before closing this issue, can someone please explain either here - or 
preferably in the User Guide

Thanks

Original comment by [email protected] on 31 Mar 2015 at 1:32

Attachments:

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