2017-08-01 6 views
0

私は、以下の具体的なクラスがあります。オリカマッパー - フィールドのサブタイプ

public class A1 {} 

public class B1 extends A1 {} 

public class A2 {} 

public class B2 extends A2 {} 

public class B3 extends A2 {} 

を、A2は、多くのサブタイプ(B2を持っているので、私はMapperFacade.map(b1Instance, A2.class)

をマッピングする際B2インスタンスを取得したいのですが、私はこれを必要とし、 B3)、必要に応じて適切なマップを作成する必要があります。

オリカでこれを達成することは可能ですか?同じ問題に直面する人々のために

答えて

0

、私は

mapperFactory.classMap(SOURCE.class, DEST.class) 
        .customize(new CustomMapper<SOURCE, DEST>() { 
     @Override 
     public void mapAtoB(SOURCE source, DEST dest, MappingContext context) { 

      //verifies the type to instantiate 
      private A2 a2 = isB2() ? new B2() : new B3;    
      //use the mapper for the class (will use the B2 or B3 mapper) 
      mapperFacade.map(source.getA2(), a2); 
      // set the field into the dest object 
      dest.setB1(a2); 

     } 
} 
をインスタンス化するためのサブタイプである確認し、このようなCustomMapperを作成、これを解決
関連する問題