Class BasePersist

java.lang.Object
io.github.vitalforge.persistlib.BasePersist

public class BasePersist extends Object
Base class for persisting objects to and from YAML files.
  • Constructor Details

    • BasePersist

      public BasePersist()
      Creates a new instance of the BasePersist.
  • Method Details

    • loadFromYaml

      public <T> T loadFromYaml(String file, Class<T> clazz)
      Loads an object from a YAML file.
      Type Parameters:
      T - The type of the object to load.
      Parameters:
      file - The file from which to load the object.
      clazz - The class of the object to load.
      Returns:
      The object loaded from the YAML file.
    • update

      public <T> T update(T instance, PersistData<T,Map<String,Object>> data)
      Updates an object with persisted data.
      Type Parameters:
      T - The type of the object to update.
      Parameters:
      instance - The object to update.
      data - The persisted data to use for the update.
      Returns:
      The updated object.
    • create

      public <T> T create(Map<String,Object> data, Class<T> clazz)
      Creates an object from persisted data.
      Type Parameters:
      T - The type of the object to create.
      Parameters:
      data - The persisted data from which to create the object.
      clazz - The class of the object to create.
      Returns:
      The object created from the persisted data.
    • createDump

      public Map<String,Object> createDump(Object instance, boolean withSuper)
      Creates persisted data from an object.
      Parameters:
      instance - The object from which to create the persisted data.
      withSuper - Whether to include fields from superclasses.
      Returns:
      The persisted data created from the object.
    • saveToYaml

      public void saveToYaml(Object instance, String file, boolean withSuper)
      Saves an object to a YAML file.
      Parameters:
      instance - The object to save.
      file - The file to which to save the object.
      withSuper - Whether to include fields from superclasses.
    • saveToYaml

      public void saveToYaml(Object instance, String file)
      Saves an object to a YAML file.
      Parameters:
      instance - The object to save.
      file - The file to which to save the object.