Custom Converter Dozer - Exception List of List

1.3k views Asked by At

I have an object like

public class Foo{

    private List<List<AnotherFoo>> anotherFooList;
}

and I have a DTO object like

public class FooDTO{

    private List<List<AnotherFooDTO>> anotherFooList;
}

On regular dozer converter I have an exception, because this is a dozer issue like is said here: Map list of lists with Dozer

So I try made a custom converter for this field threw a bean like this

<bean id="customConverterBean" class="com.bla.CustomConverterBean">
    <constructor-arg value="[L[Lcom.bla.AnotherFoo;;" />
    <constructor-arg value="[L[Lcom.bla.AnotherFooDTO;;" />
</bean>

<mapping>
    <class-a>com.bla.Foo</class-a>
    <class-b>com.bla.FooDTO</class-b>
    <field custom-converter-id="customConverterBean"><a>anotherFooList</a><b>anotherFooList</b></field>
</mapping>

and my class:

public class CustomConverterBean extends DozerConverter<List<List<AnotherFoo>>, List<List<AnotherFooDTO>>> {

    public CustomConverterBean(Class<List<List<AnotherFoo>>> prototypeA, Class<List<List<AnotherFooDTO>>> prototypeB) {
        super(prototypeA, prototypeB);
    }

    @Override
    public List<List<TrSectionDTO>> convertTo(List<List<AnotherFoo>> source, List<List<AnotherFooDTO>> destination) {
        if(source==null){
            return null;
        }
        return null;
    }

    @Override
    public List<List<AnotherFoo>> convertFrom(List<List<AnotherFooDTO>> source, List<List<AnotherFoo>> destination) {
        return null;
    }
}

But when Trying to convert I have an exception:

org.dozer.MappingException: Destination Type (java.util.List) is not accepted by this Custom Converter (com.bla.CustomConverterBean)!
    at org.dozer.DozerConverter.convert(DozerConverter.java:64)
    ...

Anyone have a clue of how to solve this?

0

There are 0 answers