KryoCloneUtils { @SuppressWarnings("unchecked") public static <SRC> SRC cloneObject(Kryo kryo, SRC src) { kryo.setClassLoader(src.getClass().getClassLoader()); ByteArrayOutputStream bos = null; Output output; Input input = null; try { bos = new ByteArrayOutputStream(); output = new Output(bos); kryo.writeObject(output, src); output.close(); input = new Input(bos.toByteArray()); return (SRC)kryo.readObject(input, src.getClass()); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(bos); } } @SuppressWarnings("unchecked") private  KryoCloneUtils(Kryo kryo, T t); T getClone(); @SuppressWarnings("unchecked") T[] getClones(int num); @SuppressWarnings("unchecked") static SRC cloneObject(Kryo kryo, SRC src); static SRC cloneObject(SRC src); static KryoCloneUtils<SRC> createCloneUtils(SRC template); static KryoCloneUtils<SRC> createCloneUtils(Kryo kryo, SRC template);  }
@Test public void testCloneObject() throws Exception { TestEntity from = getTestEntity(5); TestEntity to = KryoCloneUtils.cloneObject(from); assertFalse(from == to); assertEquals(from, to); assertFalse(from.transientProp.equals(to.transientProp)); }