Skip to content

JsonWorkspace.CreateWriter Method

Definition

Namespace: Corvus.Text.Json
Assembly: Corvus.Text.Json.dll
Source: JsonWorkspace.cs

CreateWriter(IBufferWriter<byte>)

Creates a new, dedicated UTF-8 JSON writer that writes to the specified buffer writer.

public Utf8JsonWriter CreateWriter(IBufferWriter<byte> bufferWriter)

Parameters

Name Type Description
bufferWriter IBufferWriter<byte> The buffer writer to write JSON data to.

Returns

Utf8JsonWriter

A new UTF-8 JSON writer configured with the workspace options.

Remarks

Unlike RentWriter, the returned writer is not drawn from the thread-local writer cache, so it carries no thread affinity and is safe to hold across an await boundary — for example while streaming a response whose continuations may resume on a different thread. The caller owns the returned writer and must dispose it (via Dispose or DisposeAsync) when finished. Do not pass it to ReturnWriter.

Applies To

Product Versions
.NET 9, 10
.NET Standard 2.0, 2.1

Collaborate with us on GitHub

The source for this content can be found on GitHub, where you can also create and review issues and pull requests.

Open an issue