-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Automatic mapping of Map<String, Collection<CustomType>> #922
Copy link
Copy link
Open
Labels
Milestone
Description
Hello,
So currently (1.1.0-SNAPSHOT), we have automatic mapping of List<> and Set<>, and Map<>.
But if you combine both Map<K, Collection<V>>, mapstruct is not generating implicit mappers.
public class TypeA {
}
public class TypeB {
}
public class Test1 {
private TypeA type;
private List<TypeA> list;
private Set<TypeA> set;
private Map<TypeA, String> mapKey;
private Map<String, TypeA> mapValue;
private Map<String, List<TypeA>> mapOfList;
public TypeA getType() {
return type;
}
public void setType(TypeA type) {
this.type = type;
}
public List<TypeA> getList() {
return list;
}
public void setList(List<TypeA> list) {
this.list = list;
}
public Set<TypeA> getSet() {
return set;
}
public void setSet(Set<TypeA> set) {
this.set = set;
}
public Map<TypeA, String> getMapKey() {
return mapKey;
}
public void setMapKey(Map<TypeA, String> mapKey) {
this.mapKey = mapKey;
}
public Map<String, TypeA> getMapValue() {
return mapValue;
}
public void setMapValue(Map<String, TypeA> mapValue) {
this.mapValue = mapValue;
}
public Map<String, List<TypeA>> getMapOfList() {
return mapOfList;
}
public void setMapOfList(Map<String, List<TypeA>> mapOfList) {
this.mapOfList = mapOfList;
}
}
public class Test2 {
private TypeB type;
private List<TypeB> list;
private Set<TypeB> set;
private Map<TypeB, String> mapKey;
private Map<String, TypeB> mapValue;
private Map<String, List<TypeB>> mapOfList;
public TypeB getType() {
return type;
}
public void setType(TypeB type) {
this.type = type;
}
public List<TypeB> getList() {
return list;
}
public void setList(List<TypeB> list) {
this.list = list;
}
public Set<TypeB> getSet() {
return set;
}
public void setSet(Set<TypeB> set) {
this.set = set;
}
public Map<TypeB, String> getMapKey() {
return mapKey;
}
public void setMapKey(Map<TypeB, String> mapKey) {
this.mapKey = mapKey;
}
public Map<String, TypeB> getMapValue() {
return mapValue;
}
public void setMapValue(Map<String, TypeB> mapValue) {
this.mapValue = mapValue;
}
public Map<String, List<TypeB>> getMapOfList() {
return mapOfList;
}
public void setMapOfList(Map<String, List<TypeB>> mapOfList) {
this.mapOfList = mapOfList;
}
}
@Mapper
public interface TestMapper {
TypeB mapAToB(TypeA typeA);
Test2 map1To2(Test1 test1);
}I get a :
TestMapper.java:9: error: Can't map property "java.util.Map<String,List<TypeA>> mapOfList" to "java.util.Map<String,List<TypeB>> mapOfList". Consider to declare/implement a mapping method: "java.util.Map<String,List<TypeB>> map(java.util.Map<String,List<TypeA>> value)".
I would expect mapstruct to handle Collection<> as Map key or value type automatically.
Thanks.
Olivier
Reactions are currently unavailable