Hello,
we have some issues with complex mappings with providers and converters in version 0.5.1.
public class PrescribedPropertyToPrescribedPropertyTOMap extends PropertyMap<PrescribedProperty, PrescribedPropertyTO> {
@Override
protected void configure() {
withProvider(new DataTypeTOProvider<DataTypeTO>())
.using(new DataTypeToDataTypeTOConverter())
.map(source.getDataType())
.setDataType(null);
map().getDataType().setId(source.getDataType().getId());
}
}
Problem with new version 0.5.1 is:
our DataTypeTOProvider returns object of correct type witch is not mapped from source object yet. But this object is stored to MappingContextImpl.sourceToDestination map.
Next in mapping phase source object is recognized as already mapped and mapping is skipped - we get destination partialy unmapped.
public class MappingEngineImpl
...
public <S, D> D map(MappingContext<S, D> context) {
MappingContextImpl<S, D> contextImpl = (MappingContextImpl<S, D>) context;
Class<D> destinationType = context.getDestinationType();
// Resolve some circular dependencies
if (!Iterables.isIterable(destinationType)) {
D circularDest = contextImpl.destinationForSource();
if (circularDest != null) //here is mapping skipped
return circularDest;
}
We temporary fixed source code of modelmapper - object returned from provider we are do not storing to MappingContextImpl.sourceToDestination map.
But I don't know if there is some my misunderstanding of provider role in modelmapper. Because after my change fails test "shouldUseTypeMapPropertyProvider()". I understand this test that value returned from provider have higher priority than value eventually mapped from source.
Thanks Jan