private Mapper<Object, Object> resolveMapper(final Type<?> sourceType, final Type<?> destinationType, final MappingContext context) { final MapperKey mapperKey = new MapperKey(sourceType, destinationType); Mapper<Object, Object> mapper = mapperFactory.lookupMapper(mapperKey, context); if (mapper == null) { throw new IllegalStateException(String.format("Cannot create a mapper for classes : %s, %s", destinationType, sourceType)); } if ((!mapper.getAType().equals(sourceType) && mapper.getAType().equals(destinationType)) || (!mapper.getAType().isAssignableFrom(sourceType) && mapper.getAType().isAssignableFrom(destinationType))) { mapper = ReversedMapper.reverse(mapper); } return mapper; }
Mapper<Object, Object> resolveMapper(Type<?> sourceType, Type<?> destinationType) { final MapperKey mapperKey = new MapperKey(sourceType, destinationType); Mapper<Object, Object> mapper = mapperFactory.lookupMapper(mapperKey); if (mapper == null) { throw new IllegalStateException(String.format("Cannot create a mapper for classes : %s, %s", destinationType, sourceType)); } if ((!mapper.getAType().equals(sourceType) && mapper.getAType().equals(destinationType)) || (!mapper.getAType().isAssignableFrom(sourceType) && mapper.getAType().isAssignableFrom(destinationType))) { mapper = ReversedMapper.reverse(mapper); } return mapper; }
public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { if (code.isDebugEnabled()) { Mapper<Object, Object> mapper = mapperFactory.lookupMapper( new MapperKey(source.type(), destination.type()), code.getMappingContext()); Type<?> sourceType; Type<?> destType; if (mapper.getAType().isAssignableFrom(source.type())) { sourceType = mapper.getAType(); destType = mapper.getBType(); } else { sourceType = mapper.getBType(); destType = mapper.getAType(); } code.debugField(fieldMap, "mapping using registered Mapper<" + sourceType + "," + destType + ">"); } return super.generateMappingCode(fieldMap, source, destination, code); } }