我有两个类。我的基类:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class BaseRequest {
@NotNull
@JsonProperty("dateTransaction")
private String dateTransaction;
@NotNull
@JsonProperty("hourTransaction")
private String hourTransaction;
}
还有我的另一个班。这个类扩展了BaseRequest类。
public class AddClass extends BaseRequest {
@Setter
@Getter
private String additionalData60;
}
当我尝试创建一个映射器将我的AddClass转换为OtherClass:时
@Component
@Mapper(componentModel = "spring", uses = {})
public interface OtherMapper{
@Mappings({
@Mapping(source = "hourTransaction", target = "timeTransaction"),
@Mapping(source = "dateTransaction", target = "dateTransaction"),
@Mapping(source = "additionalData60", target = "additionalData60"),
})
OtherClass toOtherClass(AddClass addClass);
}
当我运行我的构建时,我收到了这个错误:
错误:(22,13(java:没有名为"的属性;dateTransaction;源参数中存在。你是说";null";?
MapStruct与Lombok一起工作时没有问题。
但是,如果您已根据Lombok变更日志升级到Lombok 1.18.16,则需要添加
lombok-mapstruct-binding
渐变:
annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.1.0"
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.1.0</version>
</path>