Package utils

Class DeepCopier

java.lang.Object
utils.DeepCopier

public final class DeepCopier extends Object
Utility class providing methods to perform deep copies of objects using either:
  • Java Serialization (forced for Attribute trees and preferred for Serializable objects)
  • Gson-based JSON serialisation (fallback for non-Attribute, non-Serializable types)

This approach ensures users don't need to register Attribute subclasses for Gson.

  • Method Details

    • deepCopy

      public static <T> T deepCopy(T original, Class<T> clazz)
      Creates a deep copy of the given object.

      Uses Java serialization for Attribute subclasses or Serializable objects. Falls back to Gson if neither applies.

      Type Parameters:
      T - the type of the object
      Parameters:
      original - the object to be copied
      clazz - the class of the object (used only for Gson fallback)
      Returns:
      a deep copy of the original object
    • deepCopy

      public static <T> T deepCopy(T original, Type typeOfT)
      Creates a deep copy of the given object using a specified Type. Always uses Gson (no Attribute handling).
      Type Parameters:
      T - the type of the object
      Parameters:
      original - the object to be copied
      typeOfT - the specific type information of the object
      Returns:
      a deep copy of the original object