Oleksandr Onopriienko
Oleksandr Onopriienko

Reputation: 139

Use interface as source in Dozer mappings

Is it possible to use Interface as source in Dozer mappings? I have interface as source

public interface Data {

@Mapping("sourceId")
@Value("#source_id}")
Long getSourceID();  }

Dto as target :

public class DataDTO {
private Long sourceId;  }

Is it possible to automatically map fields via annotation mappings? Now, after calling dozerBeannMapper.map(source,DataDTO.class)

I only have null in field value`

Upvotes: 0

Views: 299

Answers (1)

John Camerin
John Camerin

Reputation: 722

Yes, this is possible. Dozer is aware of an objects class hierarchy. It tries to find a mapping declaration that most closely matches the source object's type and the destination class type. The destination, DataDTO, must be a concrete class with a default constructor, unless you provide a bean factory or some other instruction for Dozer on how to instantiate the instance. What is not clear from your question is "source". Can you update the question with details on the source variable, its class def and the code that is instantiating it before calling the mapping function?

Upvotes: 0

Related Questions