Skip to content

Why is Dozer is not calling my custom converter for a class #842

@swaranga-netflix

Description

@swaranga-netflix

Whats your runtime?

  • Dozer version: 5.4.0
  • OS version: Ubuntu 22.04
  • JDK version: 8

Whats the problem?

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;
}

Observed Results:

The above code prints b = B(val2=null). I also added print statements in the converter and verified the methods are not being called.

Expected Results:

Looking at the setCustomConverters method, I expected that my custom converter will be called but that is not the case

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions