In order to write the minimum amount of code required, I'm trying to let ModelMapper generate its implicit mapping and only write explicit property mappings for those properties that it couldn't auto-map.
If I let ModelMapper generate an implicit mapping using:
modelMapper.createTypeMap(SourceType.class, DestType.class);
it complains about setSomeId
having multiple possible mappings. I then tried to fix just that using:
modelMapper.addMappings(new PropertyMap<SourceType, DestType>() {
protected void configure() {
map().setSomeId(source.getProperty().getWeirdID());
}
});
However, I found that ModelMapper still complains, because an exception is actually thrown on createTypeMap
, so it doesn't have a chance to reach my custom mapping code.
If I invert both statements, I get an error:
java.lang.IllegalStateException: A TypeMap already exists for class SourceType and class DestType
If I leave out createTypeMap
completely, ModelMapper complains about missing mappings for all other properties of the DestType
(those who it was able to map automatically with createTypeMap
).
I found no explicit clue in the Documentation whether mixing implicit with explicit mappings is supported and how it's done.
Can anyone help?