2

我正在尝试使用 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确实具有不需要映射的其他属性。该错误表示编译问题,但我没有找到任何问题。此外,我尝试添加unmappedTargetPolicy = ReportingPolicy.IGNORE在我的映射器类级别尝试过,只是为了避免这是由未映射的属性引起的,但仍然没有解决方案。

4

1 回答 1

4

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

更新后,您将看到更好的错误消息,并且您将确切知道映射中的问题是什么。

通过首先查看这个,看起来那个目标@Mapping(source = "itemDetailsType", target = "ItemDetailsType")是错误的。你确定你需要一个大写字母吗?

于 2017-05-01T20:46:58.370 回答