Class ObjectConverter

java.lang.Object
com.electronwill.nightconfig.core.conversion.ObjectConverter

public final class ObjectConverter extends Object
Converts Java objects to configs and vice-versa.
  • Constructor Details

    • ObjectConverter

      public ObjectConverter(boolean bypassTransient, boolean bypassFinal)
      Creates a new ObjectConverter with advanced parameters.
      Parameters:
      bypassTransient - true to use (parse or write) a field even if it's transient
      bypassFinal - true to write a field even if it's final
    • ObjectConverter

      public ObjectConverter()
      Creates a new ObjectConverter with the default parameters. This is equivalent to new ObjectConverter(false, true).
      See Also:
  • Method Details

    • toConfig

      public void toConfig(Object o, Config destination)
      Converts an Object to a Config.
      Parameters:
      o - the object to convert
      destination - the Config where to put the values into
    • toConfig

      public void toConfig(Class<?> clazz, Config destination)
    • toConfig

      public <C extends Config> C toConfig(Object o, Supplier<C> destinationSupplier)
      Converts an Object to a Config.
      Type Parameters:
      C - the destination's type
      Parameters:
      o - the object to convert
      destinationSupplier - a Supplier that provides the Config where to put the values into
      Returns:
      the Config obtained from the Supplier
    • toConfig

      public <C extends Config> C toConfig(Class<?> clazz, Supplier<C> destinationSupplier)
    • toObject

      public void toObject(UnmodifiableConfig config, Object destination)
      Converts a Config to an Object.
      Parameters:
      config - the config to convert
      destination - the Object where to put the values into
    • toObject

      public <O> O toObject(UnmodifiableConfig config, Supplier<O> destinationSupplier)
      Converts a Config to an Object.
      Type Parameters:
      O - the destination's type
      Parameters:
      config - the config to convert
      destinationSupplier - a Supplier that provides the Object where to put the values into
      Returns:
      the object obtained from the Supplier