factory.registerClassMap(ClassMapBuilder.map(OneOtherElement.class, OneOtherElementDTO.class).byDefault().toClassMap());
}
@Test
public void testHibernateProxyLike() {
MapperFactory factory = new DefaultMapperFactory.Builder().unenhanceStrategy(new UnenhanceStrategy() {
@SuppressWarnings("unchecked")
public <T> Type<T> unenhanceType(T object, Type<T> type) {
if (object instanceof PolicyElementProxy)
return (Type<T>) ((PolicyElementProxy) object).getTargetClass();
return type;
}
@SuppressWarnings("unchecked")
public <T> T unenhanceObject(T object, Type<T> type) {
if (object instanceof PolicyElementProxy)
return (T) ((PolicyElementProxy) object).getTarget();
return object;
}
}).build();
configureMapperFactory(factory);
Policy policy = new Policy();
Set<PolicyElement> elements = new HashSet<PolicyElement>();
CustomerElement target = new CustomerElement();
target.setName("Adil");
elements.add(new PolicyElementProxy(target));
elements.add(new ProductElement());
elements.add(new OtherElement());
elements.add(new OneOtherElement());
policy.setElements(elements);
PolicyDTO dto = factory.getMapperFacade().map(policy, PolicyDTO.class);
Assert.assertEquals(elements.size(), dto.getElements().size());
for (PolicyElementDTO element: dto.getElements()) {
if (element instanceof CustomerElementDTO) {