matrezz matrezz - 1 year ago 171
Java Question

Orika mapper - map to List<String>

I have one object with the field

and I want to map it to a second object with field
. I need to map 2 objects. I can not find the way.

Situation map class One -> class Two :

public class One {
String field11;
List<AnotherObject> field12;

public class AnotherObject {
String field31;
String field32;

public class Two {
String field21;
List<String> field22;

mapperFactory.classMap(One.class, Two.class)
.fieldAToB("field11", "field21") //ok
.fieldAToB("field12{field31}", "field22") //KO //because this is String (end element) --- > List<String>

The real business is much bigger than the example so I rule out making a custom mapper.

Answer Source

You have to map it like this:

mapperFactory.classMap(One.class, Two.class)
    .fieldAToB("field11", "field21") //ok
    .fieldAToB("field12{field31}", "field22{}") //ok

Notice the empty braces {}

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download