2016-02-11 81 views
0

Mapstruct找不到屬性的通用類型。我們舉一個例子來說明我想要做什麼。MapStruct - 如何指定屬性的泛型?

考慮以下DTOS:

​​

我嘗試實施以下映射:

@Mapper 
public interface OccupantMapper { 
    ListForm<Person> test(ListForm<PersonDto> person); 

    Collection<Person> toPersons (Collection<PersonDto> persons); 
} 

但這裏的mapstruct產生什麼樣的一部分:

ListForm<Person> listForm= new ListForm<Person>(); 
if (occ.getAjouts() != null) { 
     if (listForm.getAjouts() != null) { 
      // problem here, mapstruct can't find the type of the attribute 
      Collection<T> targetCollection = person.getAdds(); 
      if (targetCollection != null) { 
       listForm.getAjouts().addAll(targetCollection); 
      } 
     } 
    } 

正如你可以在下面的代碼中看到,mapstruct找不到目標集合的類型。而且它不會將PersonDto的列表轉換爲Person列表。這是地圖應該產生的。

Collection<Occupant> targetCollection = toPersons(person.getAdds()); 

你能告訴我,如果它是一個錯誤?如果有修復?或者我應該以不同的方式做? Thks,

回答

0

它已在MapStruct 1.1.0.Beta1中發佈更正

0

你可以自己從最新的主人(https://github.com/mapstruct/mapstruct)建立MapStruct,看看這是否解決了你的問題?我上週修正了一個相關的bug,我認爲這與你的問題基本相同。

您只需運行「mvn clean install」,並參考項目中依賴關係的SNAPSHOT版本。