【发布时间】:2021-09-13 16:56:42
【问题描述】:
由于从不相关的库进行版本升级,我们的 DTO 拥有流畅的设置器。基本上是一件好事,但现在 Orika 无法映射属性
public class DebugOrikaTest {
@Test
public void simpleToFluent() {
final MapperFacade mapper = new ConfigurableMapper();
final SimpleWithBoolean a = new SimpleWithBoolean();
a.setFoo(Boolean.TRUE);
a.setBar("foobar");
final FluentWithBoolean b = new FluentWithBoolean();
// act
mapper.map(a, b);
// assert
Assertions.assertEquals("foobar", b.getBar());
Assertions.assertTrue(b.isFoo());
}
@Test
public void simpleToOther() {
final MapperFacade mapper = new ConfigurableMapper();
final SimpleWithBoolean a = new SimpleWithBoolean();
a.setFoo(Boolean.TRUE);
a.setBar("foobar");
final OtherWithBoolean b = new OtherWithBoolean();
// act
mapper.map(a, b);
// assert
Assertions.assertEquals("foobar", b.getBar());
Assertions.assertTrue(b.isFoo());
}
public static class SimpleWithBoolean {
private Boolean foo;
private String bar;
public Boolean isFoo() {
return foo;
}
public void setFoo(Boolean foo) {
this.foo = foo;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
public static class FluentWithBoolean {
private Boolean foo;
private String bar;
public Boolean isFoo() {
return foo;
}
public FluentWithBoolean setFoo(Boolean foo) {
this.foo = foo;
return this;
}
public String getBar() {
return bar;
}
public FluentWithBoolean setBar(String bar) {
this.bar = bar;
return this;
}
}
public static class OtherWithBoolean {
private Boolean foo;
private String bar;
public Boolean isFoo() {
return foo;
}
public void setFoo(Boolean foo) {
this.foo = foo;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
}
simpleToOther 测试为绿色,但 simpleToFluent 失败。有没有办法配置 Orika 将标准 JavaBean setter 映射到 fluent setter?
【问题讨论】: