Orika mapper - 映射到List <string>

时间:2016-11-08 21:00:45

标签: java mapper orika

我有一个字段为List<AnotherObject>的对象,我想将其映射到第二个字段为List<String>的对象。我需要映射2个对象。我找不到路。

情境地图第一类 - &gt;第二课:

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>

真正的业务比示例大得多,所以我排除制作自定义映射器。

1 个答案:

答案 0 :(得分:4)

你必须像这样映射:

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

注意空括号{}