[英]Orika Generic Collection Custom Mapping
Orika支持泛型類型,但是我很難使其與泛型集合一起使用。 由於Orika不支持不同的收集策略(累積,非累積,孤立刪除),因此我需要編寫一個自定義映射器來滿足我的要求。
問題在於Orika沒有應用此映射器,而是嘗試使用常規的集合映射邏輯。
Type<List<Document>> DOCUMENT_LIST = new TypeBuilder<List<Document>>() {}.build();
Type<List<DocumentRepresentation>> DOCUMENT_REP_LIST = new TypeBuilder<List<DocumentRepresentation>>() {}.build();
mapperFactory.classMap(DOCUMENT_LIST, DOCUMENT_REP_LIST)
.mapNulls(true)
.mapNullsInReverse(true)
.customize(new NonCumulativeListMapperDocumentToDocumentRepresentation())
.register();
public class NonCumulativeListMapperDocumentToDocumentRepresentation
extends CustomMapper<List<Document>, List<DocumentRepresentation>> {
//mapping logic
}
我還嘗試在父映射中顯式設置類型列表
.fieldMap("documents", "documents")
.aElementType(Document.class)
.bElementType(DocumentRepresentation.class)
.add()
但這也沒有得到解決。
關於我所缺少的任何提示嗎?
這可以通過注冊您的自定義映射器來完成:
mapperFactory.registerMapper(new NonCumulativeListMapperDocumentToDocumentRepresentation());
當Orika必須映射DOCUMENT_LIST DOCUMENT_REP_LIST時,它將在以后使用。 不需要最后的fieldMap配置。
有關在Orika中合並集合的更多信息,請參考此簡單測試(CustomMergerTest) 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.