404-not-find / orika

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

Map values not converted from a list #166

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.

public class Name {
  public String first;
}

public class Person {
  public List<Name> names;
}

public class PersonDto {
  public Map<String, Name> personalNames;
}

And the mapping:

MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Person.class, PersonDto.class) //
        .field("names{first}", "personalNames{key}") // ok
    .field("names{}", "personalNames{value}") // throws exception
    .byDefault() //
    .register();

The mapping:

.field("names{}", "personalNames{value}")

throws the exception:

Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to 
test.Name

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

The element from the list "names" should be mapped to the value of the map.

Original issue reported on code.google.com by ice.ta...@gmail.com on 1 Jul 2014 at 12:14

GoogleCodeExporter commented 8 years ago
This problem has not been resolved and is particularly frustrating because it 
is contained in the Orika User Guide:
http://orika-mapper.github.io/orika-docs/mappings-via-classmapbuilder.html

I would think it incredible that the User Guide code has not been tested, and 
so I assume there is something missing or that is assumed the new user will know

Is it possible to include complete source files for this example - rather than 
code snippets - to ensure the new user understands?

Versions tested are 1.4.2 (as per User Guide) and 1.4.5 (latest)

Original comment by jrandomu...@gmail.com on 30 Mar 2015 at 2:47