### Question:
KryoUtil { @SuppressWarnings ( value = {"unchecked"} ) static public <S extends Serializable> S clone(Kryo kryo, S object){ DirectByteArrayOutputStream buffer = new DirectByteArrayOutputStream(1024 * 1024); try(Output output = new Output(buffer)){ kryo.writeClassAndObject(output, object); } try(Input input = new Input(buffer.getInputStream())){ return (S)kryo.readClassAndObject(input); } } private  KryoUtil(); static void init(Kryo kryo); static void register(Kryo kryo); @SuppressWarnings ( value = {"unchecked"} ) static S clone(Kryo kryo, S object);  }### Answer:
@Test public void referenceTest(){ Node leftChild = new LeafNode() .setPredicate(True.INSTANCE); Node rightChild = new LeafNode() .setPredicate(False.INSTANCE); Node parent = new BranchNode() .setPredicate(True.INSTANCE) .setDefaultChild(leftChild) .addNodes(leftChild, rightChild); Node clonedParent = KryoUtil.clone(this.kryo, parent); List<Node> clonedChildren = clonedParent.getNodes(); assertNotSame(parent, clonedParent); Node clonedLeftChild = clonedChildren.get(0); Node clonedRightChild = clonedChildren.get(1); assertSame(clonedParent.getDefaultChild(), clonedLeftChild); assertNotSame(leftChild, clonedLeftChild); assertNotSame(rightChild, clonedRightChild); assertNotSame(parent.getPredicate(), clonedParent.getPredicate()); assertSame(clonedParent.getPredicate(), clonedLeftChild.getPredicate()); }
@Test public void inlineTableTest() throws Exception { PMML pmml = ResourceUtil.unmarshal(InlineTableTest.class); KryoUtil.clone(this.kryo, pmml); }
@Test public void mixedContent() throws Exception { PMML pmml = ResourceUtil.unmarshal(MixedContentTest.class); KryoUtil.clone(this.kryo, pmml); }