Question

Suppose I have a class:

class CollectionWrapper {
    private List<Address> addresses;

    public List<Address> getAddresses() {
        if (addresses == null) {
            addresses = new ArrayList<Address>();
        }
        return addresses;
    }
}

class SourceClass {
    private CollectionWrapper collectionWrapper;
    //getters and setters are omited
}

class DestinationClass {
    private List<AddressDto> addresses;
    //getters and setters are omited
}

class Address {
    String street;
    Integer number;
}

class AddressDto {
    String street;
    Integer number;
}

Obviously code below is not correct:

class MyCustomeConverter extends DozerConverter<CollectionWrapper, List<AddressDto>> {
    List<AddressDto> convertTo (CollectionWrapper source, List<AddressDto> destination) {
        List<AddressDto> result = new ArrayList<AddressDto>();
        Mapper mapper = new DozerBeanMapper();//INCORRECT !!!!
        for (Address address : source.getAddresses()) {
            result.add(mapper.map(address, AddressDto.class));
        }
        return result;
    }

    //further methods are ommited
}

So the question is how I can use Dozer conversion for primitives inside CustomConverter?

Was it helpful?

Solution

See chapter "Data Structure Conversions" from documentation and use org.dozer.MapperAware interface.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top