Class ObjectConverter
- java.lang.Object
-
- com.electronwill.nightconfig.core.conversion.ObjectConverter
-
public final class ObjectConverter extends java.lang.ObjectConverts Java objects to configs and vice-versa.
-
-
Constructor Summary
Constructors Constructor Description ObjectConverter()Creates a new ObjectConverter with the default parameters.ObjectConverter(boolean bypassTransient, boolean bypassFinal)Creates a new ObjectConverter with advanced parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidtoConfig(java.lang.Class<?> clazz, Config destination)<C extends Config>
CtoConfig(java.lang.Class<?> clazz, java.util.function.Supplier<C> destinationSupplier)voidtoConfig(java.lang.Object o, Config destination)Converts an Object to a Config.<C extends Config>
CtoConfig(java.lang.Object o, java.util.function.Supplier<C> destinationSupplier)Converts an Object to a Config.voidtoObject(UnmodifiableConfig config, java.lang.Object destination)Converts a Config to an Object.<O> OtoObject(UnmodifiableConfig config, java.util.function.Supplier<O> destinationSupplier)Converts a Config to an Object.
-
-
-
Constructor Detail
-
ObjectConverter
public ObjectConverter(boolean bypassTransient, boolean bypassFinal)Creates a new ObjectConverter with advanced parameters.- Parameters:
bypassTransient-trueto use (parse or write) a field even if it's transientbypassFinal-trueto write a field even if it's final
-
ObjectConverter
public ObjectConverter()
Creates a new ObjectConverter with the default parameters. This is equivalent tonew ObjectConverter(false, true).- See Also:
ObjectConverter(boolean, boolean)
-
-
Method Detail
-
toConfig
public void toConfig(java.lang.Object o, Config destination)Converts an Object to a Config.- Parameters:
o- the object to convertdestination- the Config where to put the values into
-
toConfig
public void toConfig(java.lang.Class<?> clazz, Config destination)
-
toConfig
public <C extends Config> C toConfig(java.lang.Object o, java.util.function.Supplier<C> destinationSupplier)
Converts an Object to a Config.- Type Parameters:
C- the destination's type- Parameters:
o- the object to convertdestinationSupplier- 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(java.lang.Class<?> clazz, java.util.function.Supplier<C> destinationSupplier)
-
toObject
public void toObject(UnmodifiableConfig config, java.lang.Object destination)
Converts a Config to an Object.- Parameters:
config- the config to convertdestination- the Object where to put the values into
-
toObject
public <O> O toObject(UnmodifiableConfig config, java.util.function.Supplier<O> destinationSupplier)
Converts a Config to an Object.- Type Parameters:
O- the destination's type- Parameters:
config- the config to convertdestinationSupplier- a Supplier that provides the Object where to put the values into- Returns:
- the object obtained from the Supplier
-
-