Package io.github.sugarcubes.cloner


package io.github.sugarcubes.cloner
Java deep cloning library.

Clone with the default cloner:

     Order clone = Cloners.clone(order);
 

Configure a cloner once and reuse it, cloners are thread safe:

     Cloner cloner = Cloners.builder()
         // share instances of a type and its subtypes
         .typeAction(Predicates.subclass(Connection.class), CopyAction.ORIGINAL)
         // clones get no value in a field
         .fieldAction(Order.class, "cachedTotal", CopyAction.CLEAR)
         // clones get a new list in a field
         .fieldValue(Order.class, "lines", ArrayList::new)
         // clear fields with an annotation
         .fieldAction(Predicates.annotatedWith(Transient.class), CopyAction.CLEAR)
         // a custom copier of a type
         .copier(Money.class, new MoneyCopier())
         // copy with the threads of a pool
         .executor(pool)
         .build();

     Order clone = cloner.clone(order);
 

Objects which cannot be copied meaningfully (threads, open files, sockets, executors) make cloning fail with UncopyableObjectException unless the configuration decides what the clone gets. The low-level mechanisms (allocation, field access, module opening) are chosen by Toolsets.defaults() for the running JVM, see Toolset.

The guide: sugar-cubes.github.io/sugar-cubes-cloner.

See Also: