Orika ライブラリを使用して、ネストされたコレクションでフィールドをマップしたいと思います。クラスの私のフィールドは次のように定義されています。
private final List<List<Pojo>> list = new LinkedList<List<Pojo>>();
Pojo は単純な POJO クラスです。残念ながら、Orika の内部ロジックで NullPointerException が原因で MappingException が発生しました。
私は間違った方法で何かをしましたか?カスタム マッピング機能を使用する必要があるのでしょうか?
編集:
これが私のコードです:
public class Pojo {
private int field;
public int getField() {
return field;
}
public void setField(final int field) {
this.field = field;
}
}
public class Source { プライベート 最終 List> リスト = 新しい LinkedList>();
public List<List<Pojo>> getList() {
return list;
}
}
public class Destination { プライベート 最終 List> listDest = new LinkedList>();
public List<List<Pojo>> getListDest() {
return listDest;
}
}
パブリック クラス メイン {
public static void main(final String[] args) {
final MapperFactory factory = new DefaultMapperFactory.Builder().build();
factory.classMap(Source.class, Destination.class).field("list", "listDest").byDefault().register();
final Source src = new Source();
final LinkedList<Pojo> nestedList = new LinkedList<Pojo>();
final Pojo pojo = new Pojo();
pojo.setField(8978);
nestedList.add(pojo);
src.getList().add(nestedList);
final MapperFacade facade = factory.getMapperFacade();
final Destination dest = facade.map(src, Destination.class);
System.out.println(dest.getListDest().get(0).get(0).getField());
}
}
上記のコードを実行すると、次の例外が発生します。
Exception in thread "main" ma.glasnost.orika.MappingException: Error encountered while mapping for the following inputs:
rawSource=com.bbh.nested.Source@39185ce6
sourceClass=class com.bbh.nested.Source
destinationClass=class com.bbh.nested.Destination