简体   繁体   中英

Orika mapper - map to List<String>

I have one object with the field List<AnotherObject> and I want to map it to a second object with field List<String> . 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.

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 {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM