无法访问Orika类com.sun.proxy

时间:2017-10-25 08:03:45

标签: java scala java-8 orika

我正在使用Orika从Akka typed actor proxy instance映射到DTO,然后从DTO instance映射到proxy instance

Akka typed actor proxy instanceDTO类的映射很好,但是当我得到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

1 个答案:

答案 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;
    }
}