diff --git a/core/src/main/java/com/github/dozermapper/core/MappingProcessor.java b/core/src/main/java/com/github/dozermapper/core/MappingProcessor.java index fa841f4a5..8624bc1b0 100644 --- a/core/src/main/java/com/github/dozermapper/core/MappingProcessor.java +++ b/core/src/main/java/com/github/dozermapper/core/MappingProcessor.java @@ -630,10 +630,13 @@ private Object mapCollection(Object srcObj, Object srcCollectionValue, FieldMap result = addToSet(srcObj, fieldMap, Arrays.asList((Object[])srcCollectionValue), destObj); } else if (CollectionUtils.isCollection(srcFieldType) && CollectionUtils.isSet(destCollectionType)) { // Collection to Set - result = addToSet(srcObj, fieldMap, (Collection)srcCollectionValue, destObj); - } else if (CollectionUtils.isCollection(srcFieldType) && MappingUtils.isSupportedMap(destCollectionType)) { + result = addToSet(srcObj, fieldMap, (Collection) srcCollectionValue, destObj); + } else if (CollectionUtils.isList(srcFieldType) && MappingUtils.isSupportedMap(destCollectionType)) { // List to Map value - result = mapListToList(srcObj, (List)srcCollectionValue, fieldMap, destObj); + result = mapListToList(srcObj, (List) srcCollectionValue, fieldMap, destObj); + } else if (CollectionUtils.isSet(srcFieldType) && MappingUtils.isSupportedMap(destCollectionType)) { + // Set to Map value + result = mapListToList(srcObj, (Set) srcCollectionValue, fieldMap, destObj); } else if (CollectionUtils.isCollection(srcFieldType) && CollectionUtils.isList(destCollectionType)) { // List to List // Set to List diff --git a/core/src/test/java/com/github/dozermapper/core/MappingProcessorTest.java b/core/src/test/java/com/github/dozermapper/core/MappingProcessorTest.java index 79fff635a..453f8f04d 100644 --- a/core/src/test/java/com/github/dozermapper/core/MappingProcessorTest.java +++ b/core/src/test/java/com/github/dozermapper/core/MappingProcessorTest.java @@ -16,7 +16,11 @@ package com.github.dozermapper.core; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; import com.github.dozermapper.core.vo.A; import com.github.dozermapper.core.vo.B; @@ -156,5 +160,40 @@ public int hashCode() { return id; } } + public static class Source { + Map> map; -} + public Map> getMap() { + return map; + } + + public void setMap(Map> map) { + this.map = map; + } + } + + public static class Target { + Map> map; + + public Map> getMap() { + return map; + } + + public void setMap(Map> map) { + this.map = map; + } + } + + @Test + public void testSourceToTargetMapping() { + final Mapper mapper = DozerBeanMapperBuilder.create().build(); + Source source = new Source(); + Map> sourceMap = new HashMap<>(); + sourceMap.put("foo", new HashSet<>(List.of("bar"))); + source.setMap(sourceMap); + Target target = mapper.map(source, Target.class); + assertNotNull(target.getMap()); + assertEquals(source.getMap().size(), target.getMap().size()); + + } +} \ No newline at end of file