BeanReplicator extends ReplicatorTemplate implements BeanReplicatorSpi { @SuppressWarnings("unchecked") public <V> V replicateBean(V from) { return replicateBean(from, (Class<V>) from.getClass()); } BeanReplicator(BeanTransformerSpi beanTransformer);  BeanReplicator(CustomBeanTransformerSpi.Factory... customTransformerFactory);  BeanReplicator(); @SuppressWarnings("unchecked") V replicateBean(V from); @Override T replicateBean(V from, Class<T> toClass); T populate(V from, T to);  }
@Test public void test() { ComplexBean from = new ComplexBean("foo"); ComplexBean[] a = { from }; Collection<ComplexBean> col = Arrays.asList(a); from.setArray(a); from.setCollection(col); Map<String, ComplexBean> map = new HashMap<String, ComplexBean>(); map.put(from.getName(), from); from.setMap(map); from.setClazz(List.class); ComplexBean to = new BeanReplicator().replicateBean(from); assertThat(from.getName(), is("foo")); assertThat(from.getArray()[0], sameInstance(from)); assertThat(from.getCollection().iterator().next(), sameInstance(from)); assertThat(from.getMap().get(from.getName()), sameInstance(from)); assertThat(from, not(sameInstance(to))); assertThat(from.getName(), is(to.getName())); assertThat(to.getArray()[0], sameInstance(to)); assertThat(to.getArray().length, is(1)); assertThat(to.getCollection().iterator().next(), sameInstance(to)); assertThat(to.getCollection().size(), is(1)); assertThat(to.getMap().get(to.getName()), sameInstance(to)); assertThat(to.getMap().size(), is(1)); assertSame(to.getClazz(), List.class); }