@ Override public < T extends Composite < S > > T copy ( ) { try { String fullJSON = fullMapper . writeValueAsString ( this ) ; @ SuppressWarnings ( "unchecked" ) T copy = ( T ) fullMapper . readValue ( fullJSON , getClass ( ) ) ; return copy ; } catch ( IOException e ) { throw new RuntimeException ( "The attempted copy of an object failed." , e ) ; } }
This method should work for all objects . However it is very inefficient and should only be used sparingly and for unit testing .