serializeAndWrite

suspend fun <T> T.serializeAndWrite(serializer: KSerializer<T>, path: Path, append: Boolean = true, atomicMove: Boolean = false, format: StringFormat = jsonForMachines): Outcome<T>

Serializes this object and writes it to the specified path.

Creates parent directories if needed and supports appending or overwriting the file. Optionally uses an atomic move to ensure safe file writing.

Return

This object, for method chaining.

Parameters

serializer

The KSerializer to use for serialization.

path

The Path to write the serialized data to.

append

If true, appends to the file; otherwise, overwrites it (default: true).

atomicMove

If true, writes to a temporary file and moves it atomically to path (default: false).

format

The StringFormat to use for encoding (default: jsonForMachines).