【问题标题】:Mapstruct: Cannot convert from java.time.LocalDate to java.time.OffsetDateTimeMapstruct:无法从 java.time.LocalDate 转换为 java.time.OffsetDateTime
【发布时间】:2018-06-06 15:52:50
【问题描述】:
public class ClassA {
     private OffsetDateTime updateBy;
}

public class ClassB {
     private LocalDate timestamp;
}

public interface ClassABMapper {
     @Mapping(target = "updateBy", source = "classB.timestamp")
     ClassA map(ClassB classB);
}

无法将属性“java.time.LocalDate timestamp”映射到“java.time.OffsetDateTime updateBy”。考虑声明/实现一个映射方法:“java.time.OffsetDateTime map(java.time.LocalDate value)”。

我尝试在 mapper 中声明以下方法。

java.time.LocalDate map(java.time.OffsetDateTime value);

我收到错误:

错误:java.time.LocalDate 没有可访问的空构造函数。 java.time.LocalDate 映射(java.time.OffsetDateTime 值);

谁能解释一下如何进行转换?

【问题讨论】:

    标签: java-time mapstruct


    【解决方案1】:

    我创建了自己的自定义映射器,如文档 section 5.4. Invoking other mappers 中所述。这为我解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2017-08-30
      • 2014-02-10
      • 1970-01-01
      • 2021-04-27
      • 2021-12-22
      • 1970-01-01
      • 2014-10-15
      相关资源
      最近更新 更多