@Test public void cloneObject() throws Exception { AdrConfigurationServiceMock config = new AdrConfigurationServiceMock(null); AdrIconDescriptor sourceIcon = config.getDefaultIcon(); AdrIconDescriptor cloned = CloneHelper.cloneObject(sourceIcon); cloned.setComponentId(cloned.getComponentId() + 10341); assertNotEquals(sourceIcon,cloned); }
public static <T> T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(baos); ous.writeObject(source); ous.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } return cloned; }
CloneHelper { public static <T> T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(baos); ous.writeObject(source); ous.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } return cloned; } }
CloneHelper { public static <T> T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(baos); ous.writeObject(source); ous.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } return cloned; }  }
CloneHelper { public static <T> T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(baos); ous.writeObject(source); ous.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } return cloned; }  static T cloneObject(T source); }
CloneHelper { public static <T> T cloneObject(T source) { T cloned = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream ous = new ObjectOutputStream(baos); ous.writeObject(source); ous.close(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); ObjectInputStream ois = new ObjectInputStream(bais); cloned = (T) ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while cloning object: ", e); } return cloned; }  static T cloneObject(T source);  }