Role of provider in modelmapper

311 views
Skip to first unread message

Jan Matejka

unread,
Oct 16, 2012, 10:47:58 AM10/16/12
to model...@googlegroups.com
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 

Jonathan Halterman

unread,
Oct 16, 2012, 7:26:46 PM10/16/12
to model...@googlegroups.com
Hi Jan,

Your usage of Provider looks correct - to provider a source object that is yet to be populated. Is this the scenario that was causing the issue you filed on github?

https://github.com/jhalterman/modelmapper/issues/15

Cheers,
Jonathan

Jan Matejka

unread,
Oct 17, 2012, 2:40:17 AM10/17/12
to model...@googlegroups.com
Hi Jonathan,
thanks for your reply. 
Issue 15 on github has different scenario than this question. 
I try to extract from our code a test to reproduce issue in isolation. 

Cheers
Jan
Reply all
Reply to author
Forward
0 new messages