Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swaranga-netflix opened this issue Nov 3, 2022 · 0 comments
Open

Comments

@swaranga-netflix
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant