Skip to content

ParsedJsonDocumentBuilder

Definition

Namespace: Corvus.Text.Json.Internal
Assembly: Corvus.Text.Json.dll
Source: ParsedJsonDocumentBuilder.cs

A single-use, poolable IMutableJsonDocument that supports document construction via ComplexValueBuilder, and materializes the result as a self-contained ParsedJsonDocument without a serialize-and-reparse round trip.

public sealed class ParsedJsonDocumentBuilder : JsonDocument, IMutableJsonDocument, IWorkspaceManagedDocument, IJsonDocument, IDisposable

Remarks

This type backs the generated Create() factory methods, which are the ParsedJsonDocument-producing analogue of the generated CreateBuilder() methods. Unlike a JsonDocumentBuilder, this builder writes the final UTF-8 document text directly during construction: the store operations format each value straight into the text backing, the IComplexValueConstructionCallbacks hooks supply the container boundaries, and values embedded from other documents are captured into the backing at the point they are added. Property names are distinguished from string values by JSON's strict name/value alternation within an object, so the ordinary store operations need no extra signalling. The metadata rows are those built by the ComplexValueBuilder in the usual way; a side list records the text location and content length for each row as it is written, and ToParsedJsonDocument applies them in a single in-place patch pass — no second metadata table is built and no content is copied. If a property is removed during construction (for example via TryApply), the removed value's text is stranded in the backing and the document is marked dirty; a dirty document pays one compaction pass at handoff, rebuilding the text from the surviving rows. Instances are rented from a thread-local cache via Rent to avoid hot-path allocation. Dispose is idempotent and returns the instance to the cache; it is safe to call it after ToParsedJsonDocument (which disposes the builder as part of the handoff), for example from a finally block in a fault-handling path. The builder supports document construction only. Element access, mutation of an existing document, and the other IJsonDocument read operations are not supported and throw InvalidOperationException.

Inheritance

ObjectJsonDocumentParsedJsonDocumentBuilder

Implements

IMutableJsonDocument, IWorkspaceManagedDocument, IJsonDocument, IDisposable

Methods

Method Description
Dispose() Disposes the builder, returning its pooled resources and the instance itself to their pools. Disposal is idempotent.
Rent(int) static Rents a builder from the thread-local cache, ready to receive a value via ComplexValueBuilder and...
StorePrebakedValue(ReadOnlySpan<byte>)
ToParsedJsonDocument() Hands off the built value as a new, self-contained ParsedJsonDocument, and disposes this builder (returning it to the pool).

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