![](/img/trans.png)
[英]How can Orika map objects without instantiating a new destination object
[英]Orika - mapping Object (source) to Set(Collection) of Objects (destination)
我有以下課程。
// Source Classes
class SourceEmployer
{
private EmployerDetail employerDetail;
// getters/setters
}
class EmployerDetail
{
private String name;
// getters/setters
}
// Destination Classes
class DestApplication
{
private Employment employment;
// getters/setters
}
class Employment
{
private Set<EmployerDetails> employerDetails;
// getters/setters
}
class EmployerDetails
{
private String employerName;
// getters/setters
}
// Some Mapping configuration
public DestApplication getOrikaMapping(SourceEmployer source, DestApplication destination)
{
MapperFacade mapper;
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(source.getClass(), destination.getClass())
.field("employerDetail.name",
"employment.employerDetails{employerName}")
.byDefault()
.register();
mapper = mapperFactory.getMapperFacade();
DestApplication dto = mapper.map(source, DestApplication.class);
return dto;
}
當執行上面的代碼時,我遇到了以下異常...
-------------------------------------------------- -----------取消策略:ma.glasnost.orika.unenhance.BaseUnenhancer@3547efb7 -----當前狀態的最終轉儲--------------- ----------------在ma.glasnost.orika.impl.ExceptionUtility.newMappingException(ExceptionUtility.java:55)測試au.com.copl.dbaccesslayer.session.WebserviceBeanTest失敗
看來這是一個Orika錯誤,我在這里報告了它: https : //github.com/orika-mapper/orika/issues/104 。
為映射器生成的字節碼不正確,並且先聲明一個null
變量,然后嘗試訪問它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.