load

inline fun <T : Any> load(file: File): T

Loads a configuration of type T from the specified file.

This is a convenience overload that infers the KClass from the reified type parameter.

Example:

val config = YamlConfigManager.load<ServerConfig>(dataFolder.resolve("config.yml"))

Return

The deserialized and validated configuration instance.

Since

1.0

Parameters

T

The configuration data class type.

file

The YAML file to load from. Created with defaults if it does not exist.

See also

Throws

If the config cannot be loaded and no default can be created.


fun <T : Any> load(file: File, klass: KClass<T>): T

Loads a configuration of type T from the specified file.

If the file does not exist, it is created with default values derived from T's primary constructor defaults. After loading, the config is validated, errors are reported via ConfigErrorFormatter, @Env overrides are applied, and the file is re-saved to fill in any missing fields.

Loading pipeline:

  1. If the file does not exist, create it with defaults and return.

  2. Read the YAML file into a raw map.

  3. Run any registered ConfigMigrations if the file version is outdated.

  4. Deserialize the map into an instance of T, collecting validation errors.

  5. Report errors (if any) via the configured error formatter.

  6. Save the instance back to normalize formatting and fill missing defaults.

  7. Apply @Env environment variable overrides to the in-memory instance.

Example:

val config = YamlConfigManager.load<ServerConfig>(dataFolder.resolve("config.yml"))

Return

The deserialized and validated configuration instance.

Since

1.0

Parameters

T

The configuration data class type.

file

The YAML file to load from. Created with defaults if it does not exist.

klass

The KClass of the configuration type.

See also

Throws

If the config cannot be loaded and no default can be created.