相关疑难解决方法(0)

如何使用Orika映射java.time.LocalDate字段?

这是因为LocalDate不是JavaBean(它没有零参数构造函数)

要解决此问题,您需要创建LocalDateConverter:

public class LocalDateConverter extends BidirectionalConverter<LocalDate, LocalDate> {

  @Override
  public LocalDate convertTo(LocalDate source, Type<LocalDate> destinationType) {
    return (source);
  }

  @Override
  public LocalDate convertFrom(LocalDate source, Type<LocalDate> destinationType) {
    return (source);
  }

}
Run Code Online (Sandbox Code Playgroud)

然后注册添加此行:

mapperFactory.getConverterFactory().registerConverter(new LocalDateConverter());
Run Code Online (Sandbox Code Playgroud)

作为shorcut,您可以按照Adam Michalik的建议注册提供的"PassThroughConverter",这样Orika就不会尝试实现新的"LocalDate":

mapperFactory.getConverterFactory().registerConverter(new PassThroughConverter(LocalDate.class));
Run Code Online (Sandbox Code Playgroud)

java orika

10
推荐指数
2
解决办法
4341
查看次数

标签 统计

java ×1

orika ×1