我正在使用Orika从Akka typed actor proxy instance
映射到DTO
,然后从DTO instance
映射到proxy instance
。
从Akka typed actor proxy instance
到DTO
类的映射很好,但是当我得到dto实例并且我想转换回Akka类型的actor代理实例时,Orika会抛出异常
这是我的代码:
TestDaoDTO dto = mapper.map(aggregateRoot, TestDaoDTO.class);
TestAggregateRoot other = mapper.map(dto, aggregateRoot); --> this mapper fail
AggreagateRoot是class com.sun.proxy.$Proxy178
例外情况
ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class com.sun.proxy.$Proxy178 is not accessible
答案 0 :(得分:1)
您应该将代理解包到" real"类。此代码可用于此目的:
@SuppressWarnings("unchecked")
private <T> T unwrap(T object) throws Exception {
if (AopUtils.isAopProxy(object) && object instanceof Advised) {
return (T) ((Advised) object).getTargetSource().getTarget();
} else {
return object;
}
}