Dozer mapper: Override mapNull(false) of subclass with mapNull(true) of superclass

18 Views Asked by At

I've got two classes, one inheriting from the other

class A {
    String s;
}
class B extends A {}

There are also other classes inheriting from A, but they don't matter right now.

For A and B I have the following mappings:

mapping(A.class, A.class, mapNull(false));
mapping(B.class, B.class, mapNull(true));

What I'd want is if I map A to A, a null value in the source should not be written to the target, so that the target keeps it's non-null value for the field.

But when I map B to B, all null values in the source (even for fields defined in A) should be written to the target, so that the target then also has the non-null value for the field.

The first part (A -> A) works, but when I map B -> B, it behaves like the A -> A mapping, not overwriting the fields.

Essentially, the result is the same as if I didn't define the second mapping.

Is there a way to to what I want in Dozer?

PS: regarding the other classes I mentioned in the beginning, they should still all behave like the A -> A mapping.

0

There are 0 best solutions below