2017-05-18 8 views
1

빈에서 매핑하는 동안 일부 필드를 HashMap으로 제외하려고합니다.Orika bean mapper에서 필드를 제외하는 방법은 무엇입니까?

Orika 정의 :

static { 
     final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 
     mapperFactory.classMap(MyReq.class, Map.class) 
       .exclude("myproperty") 
       .byDefault() 
       .register(); 
     MAPPER = mapperFactory.getMapperFacade(); 
    } 

콩 정의 :

public class MyReq { 
    private String myproperty; 
} 

사용법 :

MyReq req = new MyReq; 
Map map = MAPPER.map(req, Map.class); 

결과 : Map 제외 myproperty 필드가 있습니다! 왜?

답변

1

또한이 문제가 발생했지만 Map 인스턴스 (사용자가 정의한 클래스가 대상 객체 인 경우에는 정상적으로 작동 함)에서만 발생합니다. 그러나 Orika에는 매핑 규칙을 정의하는 여러 가지 방법이 있으므로 다음과 같은 해결 방법이 있습니다.

mapperFactory.classMap(MyReq.class, Map.class) 
         .fieldMap("myproperty").exclude().add() 
         .byDefault() 
         .register();