我尝试使用mapstruct将本地pojo映射到自动生成的域对象。期望一个特定的复杂结构,其他一切似乎都映射,映射器实现类得到生成。以下是我得到的错误。
我的映射器类是:
@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
确实有其他不需要映射的属性。错误说编译问题,但我没有找到任何。另外我尝试添加在我的mapper类级别尝试了unmappedTargetPolicy = ReportingPolicy.IGNORE
,以避免这是由未映射的属性引起的,但仍然没有解决方案。
答案 0 :(得分:2)
这是MapStruct中的已知错误。该错误在#729中报告,已在1.1.0.Final修复。您正在使用1.0.0.Final。我强烈建议切换到1.1.0.Final或1.2.0.Beta2。
更新后,您会看到更好的错误消息,您将确切知道映射中的问题是什么。
首先看一下,看起来@Mapping(source = "itemDetailsType", target = "ItemDetailsType")
中的目标是错误的。你确定那里需要大写字母吗?