2017-05-01 3 views
0

mapstruct를 사용하여 자동 생성 된 도메인 객체에 대해 로컬 pojo 맵을 사용하려고합니다. 특정 복잡한 구조가 예상된다. 다른 모든 것은 매핑되고 매퍼 구현 클래스는 생성된다. 아래는 내가받는 오류입니다.매핑 프로세서의 내부 오류 : java.lang.NullPointerException

내 매퍼 클래스는 다음과 같습니다

@Mappings({ 
     @Mapping(source = "sourcefile", target = "sourceFILE"), 
     @Mapping(source = "id", target = "ID"), 
     @Mapping(source = "reg", target = "regID"), 
     @Mapping(source = "itemDetailsType", target = "ItemDetailsType") //This is the structure that does not map 
}) 
AutoGenDomainType map(LocalPojo localPojo); 

@Mappings({ 
     @Mapping(source = "line", target = "LINE"), 
     @Mapping(source = type", target = "TYPE") 
}) 
ItemDetailsType map(ItemDetailsTypes itemDetailsType); 

오류 :

Internal error in the mapping processor: java.lang.NullPointerException   at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.hasCompatibleCopyConstructor(MappingResolverImpl.java:547)   at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.isPropertyMappable(MappingResolverImpl.java:522) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.getTargetAssignment(MappingResolverImpl.java:202) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.access$100(MappingResolverImpl.java:153) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl.getTargetAssignment(MappingResolverImpl.java:121) at 
..... 
..... 
[ERROR] 
[ERROR] Found 1 error and 16 warnings. 
[ERROR] -> [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project uwo-services: Compilation failure 

대상 객체 ItemDetailsType 매핑 할 필요는 다른 특성을 가지고있다. 오류는 컴파일 문제를 말하지만, 나는 찾을 수 없다. 또한이 매핑되지 않은 속성에 의해 발생하는 경우 피하기 위해 내 매퍼 클래스 수준에서 unmappedTargetPolicy = ReportingPolicy.IGNORE 시도했지만 추가 시도한 있지만 여전히 솔루션입니다.

+0

비슷한 질문에 대한 답변을 찾았습니다. http://stackoverflow.com/questions/33994644/mapstruct-object-class-to-custom-class-mapping –

+0

@KarthikeyanKesavaraj 나는 그것을 확인했습니다. mapStruct를 사용하여 구조적으로 다른 복잡한 객체를 매핑하는 방법을 설명합니다. 그러나 제 경우에는 매핑 된 다른 속성과 그렇지 않은 속성이 있습니다. 그것은'NullPointerException'을 던집니다. –

답변

2

이것은 MapStruct의 알려진 버그입니다. 버그는 #729에보고되었으며, 1.1.0.Final에서 수정되었습니다. 당신은 1.0.0. 최종을 사용하고 있습니다. 1.1.0.Final 또는 1.2.0.Beta2로 전환하는 것이 좋습니다.

일단 업데이트하면 더 나은 오류 메시지가 나타나고 매핑의 문제점을 정확히 알 수 있습니다.

먼저 이것을 보면 @Mapping(source = "itemDetailsType", target = "ItemDetailsType")의 대상이 잘못되었습니다. 국회 의사당 편지가 필요하십니까?

+0

당신은 맞습니다. 1.0.0을 사용하고 있습니다. 최종 버전이 1.1.0으로 변경되었지만 오류 메시지가 나타나지 않지만 실제로 원하는 클래스가 생성되었습니다. 그러나 나는 새 버전으로 변경 내용을 커밋 할 수 없습니다. 그래서'@ AfterMapping'을 사용하고 내 값을 설정하여 해결했습니다. –

관련 문제