public static <T> T copy(T orig) {
        if (orig == null) {
            return null;
        }
        try {
            // Write the object out to a byte array
            ByteArrayOutputStream fbos = new ByteArrayOutputStream();

            try (ObjectOutputStream out = new ObjectOutputStream(fbos)) {
                out.writeObject(orig);
                out.flush();
            }

            // Retrieve an input stream from the byte array and read
            // a copy of the object back in.
            try (ByteArrayInputStream fbis = new ByteArrayInputStream(fbos.toByteArray());
                 ObjectInputStream in = new ObjectInputStream(fbis))  {
                return (T) in.readObject();
            }
        } catch (IOException | ClassNotFoundException e) {
            throw new IllegalStateException("Cannot copy " + orig, e);
        }
    }
Returns a copy of the object, or null if the object cannot
be serialized.
src/main/java/io/fabric8/maven/docker/util/DeepCopy.java