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

问题描述 投票:0回答:1

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

我的mapper类是:

@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,以避免如果这是由未映射的属性,但仍然没有解决方案。

spring-mvc mapstruct
1个回答
3
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.