# LoaderSettings

## Creating a builder

Settings introduced by BoostedYAML follow builder design pattern, e.g. you may build your own settings using:

```java
LoaderSettings.builder() /*configure*/ .build()
```

## Basic settings

### Create file if absent

```java
Builder#setCreateFileIfAbsent(boolean createFileIfAbsent)
```

Sets if to create a new file and save it if it does not exist automatically.

{% hint style="warning" %}
Not effective if there is no file associated with the document.
{% endhint %}

**Default:** `true` (enabled)

### Update automatically

```java
Builder#setAutoUpdate(boolean autoUpdate)
```

If enabled, automatically calls [`YamlFile#update()`](https://dejvokep.gitbook.io/boostedyaml/getting-started/updating-a-file#updating) after the document has been loaded.

{% hint style="warning" %}
Not effective if there are no defaults associated with the document.
{% endhint %}

**Default:** `false` (disabled)

## Advanced settings

### Error labels

```java
Builder#setErrorLabel(@NotNull String label)
```

Sets custom label for error messages.

**Default:** defined by the parent method\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setLabel\(java.lang.String\))\
**Related YAML spec (v1.2.2):** -

### Detailed errors

```java
Builder#setDetailedErrors(boolean detailedErrors)
```

Sets if to print detailed error messages.

**Default:** `true`\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setUseMarks\(boolean\))\
**Related YAML spec (v1.2.2):** -

### Allow duplicate keys

```java
Builder#setAllowDuplicateKeys(boolean allowDuplicateKeys)
```

Sets if to allow duplicate keys in sections (last key wins when loading).

**Default:** `true`\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setAllowDuplicateKeys\(boolean\))\
**Related YAML spec (v1.2.2):** -

### Max collection aliases

```java
Builder#setMaxCollectionAliases(int maxCollectionAliases)
```

Sets maximum aliases a collection can have to prevent memory leaks (see [Billion laughs attack](https://en.wikipedia.org/wiki/Billion_laughs_attack)).

**Default:** defined by the parent method\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setMaxAliasesForCollections\(int\))\
**Related YAML spec (v1.2.2):** -

### Tag constructors

```java
Builder#setTagConstructors(@NotNull Map<Tag, ConstructNode> constructors)
```

Sets custom node to Java object constructors, per YAML tag.

**Default:** defined by the parent method\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setTagConstructors\(java.util.Map\))\
**Related YAML spec (v1.2.2):** [JSON schema tags](https://yaml.org/spec/1.2.2/#1021-tags), [failsafe schema tags](https://yaml.org/spec/1.2.2/#failsafe-schema)

### Schema

```java
Builder#setSchema(@NotNull Schema schema)
```

Sets custom schema to use. Schemas are used to resolve and determine object tags contained within a document. This setting replaces `setScalarResolver` available until the 1.3.6 release.

**Default:** defined by the parent method\
**Parent method docs (v2.7):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.7/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setSchema\(org.snakeyaml.engine.v2.schema.Schema\))\
**Related YAML spec (v1.2.2):** [JSON schema tags](https://yaml.org/spec/1.2.2/#1021-tags), [failsafe schema tags](https://yaml.org/spec/1.2.2/#failsafe-schema)

### Environment config

```java
Builder#setEnvironmentConfig(@Nullable EnvConfig envConfig)
```

Sets custom environment variable config.

**Default:** defined by the parent method\
**Parent method docs (v2.3):** [click](https://javadoc.io/static/org.snakeyaml/snakeyaml-engine/2.3/org/snakeyaml/engine/v2/api/LoadSettingsBuilder.html#setEnvConfig\(java.util.Optional\))\
**Related YAML spec (v1.2.2):** -


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dejvokep.gitbook.io/boostedyaml/settings/loadersettings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
