Since a version upgrade from an unrelated library, our DTOs have fluent setters. Basically a nice thing, but now Orika is failing to map properties
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;
}
}
}
The simpleToOther test is green, but simpleToFluent fails. Is there a way to configure Orika to map standard JavaBean setters to fluent setters?
The culprit (at least in Orika 1.5.2) is the IntrospectorPropertyResolver, which uses java.beans:
this will not return properties with a fluent setter. The following subclass uses Apache beanutils, which has a
FluentPropertyBeanIntrospector:The PropertyResolver then needs to be registered