I am trying to configure a custom converter for mapping between two types. I want to stick to the programmatic API and not resort to XML. But it seems Dozer is not calling my custom converter. Here is a small unit test that reproduces the problem:
@Test
public void test() {
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.setCustomConverters(singletonList(new ABConverter()));
A a = new A("001");
B b = mapper.map(a, B.class);
System.out.println("b = " + b);
}
public static class ABConverter extends DozerConverter<A, B> {
public ABConverter() {
super(A.class, B.class);
}
@Override
public B convertTo(A source, B destination) {
return new B(source.val1);
}
@Override
public A convertFrom(B source, A destination) {
return new A(source.val2);
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class A {
private String val1;
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public static class B {
private String val2;
}
The above code prints b = B(val2=null). I also added print statements in the converter and verified the methods are not being called.
Looking at the setCustomConverters method, I expected that my custom converter will be called but that is not the case. I am using Dozer 5.4.0