映射处理器中的内部错误:java.lang.NullPointerException

Internal error in the mapping processor: java.lang.NullPointerException

我正在尝试使用 mapstruct 将本地 pojo 映射到自动生成的域对象。期待一个特定的复杂结构,其他一切似乎都可以映射,并且映射器实现 class 得到生成。以下是我得到的错误。

我的映射器 class 是:

@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.access0(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确实有其他不需要映射的属性。错误说编译问题,但我没有找到任何问题。我也尝试添加并在我的映射器 class 级别尝试了 unmappedTargetPolicy = ReportingPolicy.IGNORE 只是为了避免这是由未映射的属性引起的,但仍然没有解决方案。

这是 MapStruct 中的一个已知错误。该错误已在 #729 中报告,已在 1.1.0.Final 中修复。您正在使用 1.0.0.Final。我强烈建议切换到 1.1.0.Final 或 1.2.0.Beta2.

更新后您会看到更好的错误消息,并且您会确切知道映射中的问题所在。

首先看一下 @Mapping(source = "itemDetailsType", target = "ItemDetailsType") 中的目标似乎是错误的。您确定此处需要大写字母吗?