Class PersistenceLoader


public class PersistenceLoader extends Object
Performs reflective persistence of objects into DataKeys. Persist annotations are used to mark fields for annotation.
See Also:
  • Constructor Details

    • PersistenceLoader

      public PersistenceLoader()
  • Method Details

    • createRegistry

      public static <T> PersisterRegistry<T> createRegistry(Class<?> base)
    • load

      public static <T> T load(Class<? extends T> clazz, DataKey root)
      Creates an instance of the given class using the default constructor and loads it using load(Object, DataKey). Will return null if an exception occurs.
      clazz - The class to create an instance from
      root - The root key to load from
      The loaded instance
      See Also:
    • load

      public static <T> T load(T instance, DataKey root)
      Analyses the class for Fields with the Persist annotation and loads data into them using the given DataKey. If a DelegatePersistence annotation is provided the referenced Persister will be used to create the instance. This annotation can be omitted if the Persister has been registered using registerPersistDelegate(Class, Class)
      instance - The instance to load data into
      root - The key to load data from
      The instance, with persisted fields loaded
    • registerPersistDelegate

      public static void registerPersistDelegate(Class<?> clazz, Class<? extends Persister<?>> delegateClass)
      Registers a Persister redirect. Fields or constructors with the Persist annotation with a type that has been registered using this method will use the supplied Persister for (de)serialisation. The DelegatePersistence annotation will be preferred if present.
      clazz - The class to redirect
      delegateClass - The Persister class to use when loading and saving
    • save

      public static void save(Object instance, DataKey root)
      Scans the object for fields annotated with Persist and saves them to the given DataKey.
      instance - The instance to save
      root - The key to save into