@Test public void deepCopyTest() throws Exception { Object input = JsonUtils.classpathToObject( "/json/deepcopy/original.json" ); Map<String, Object> fiddle = (Map<String, Object>) DeepCopy.simpleDeepCopy( input ); JoltTestUtil.runDiffy( "Verify that the DeepCopy did in fact make a copy.", input, fiddle ); List array = (List) fiddle.get( "array" ); array.add( "c" ); array.set( 1, 3 ); Map<String,Object> subMap = (Map<String,Object>) fiddle.get( "map" ); subMap.put("c", "c"); subMap.put("b", 3 ); Object unmodified = JsonUtils.classpathToObject( "/json/deepcopy/original.json" ); JoltTestUtil.runDiffy( "Verify that the deepcopy was actually deep / input is unmodified", unmodified, input ); Object expectedModified = JsonUtils.classpathToObject( "/json/deepcopy/modifed.json" ); JoltTestUtil.runDiffy( "Verify fiddled post deepcopy object looks correct / was modifed.", expectedModified, fiddle ); }
public static Object simpleDeepCopy( Object object ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); bos.close(); byte [] byteData = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(byteData); return new ObjectInputStream(bais).readObject(); } catch ( IOException ioe ) { throw new RuntimeException( "DeepCopy IOException", ioe ); } catch ( ClassNotFoundException cnf ) { throw new RuntimeException( "DeepCopy ClassNotFoundException", cnf ); } }
DeepCopy { public static Object simpleDeepCopy( Object object ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); bos.close(); byte [] byteData = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(byteData); return new ObjectInputStream(bais).readObject(); } catch ( IOException ioe ) { throw new RuntimeException( "DeepCopy IOException", ioe ); } catch ( ClassNotFoundException cnf ) { throw new RuntimeException( "DeepCopy ClassNotFoundException", cnf ); } } }
DeepCopy { public static Object simpleDeepCopy( Object object ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); bos.close(); byte [] byteData = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(byteData); return new ObjectInputStream(bais).readObject(); } catch ( IOException ioe ) { throw new RuntimeException( "DeepCopy IOException", ioe ); } catch ( ClassNotFoundException cnf ) { throw new RuntimeException( "DeepCopy ClassNotFoundException", cnf ); } }  }
DeepCopy { public static Object simpleDeepCopy( Object object ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); bos.close(); byte [] byteData = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(byteData); return new ObjectInputStream(bais).readObject(); } catch ( IOException ioe ) { throw new RuntimeException( "DeepCopy IOException", ioe ); } catch ( ClassNotFoundException cnf ) { throw new RuntimeException( "DeepCopy ClassNotFoundException", cnf ); } }  static Object simpleDeepCopy( Object object ); }
DeepCopy { public static Object simpleDeepCopy( Object object ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); oos.close(); bos.close(); byte [] byteData = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(byteData); return new ObjectInputStream(bais).readObject(); } catch ( IOException ioe ) { throw new RuntimeException( "DeepCopy IOException", ioe ); } catch ( ClassNotFoundException cnf ) { throw new RuntimeException( "DeepCopy ClassNotFoundException", cnf ); } }  static Object simpleDeepCopy( Object object );  }