diff --git a/src/HotChocolate/Json/src/Json/JsonWriter.cs b/src/HotChocolate/Json/src/Json/JsonWriter.cs index c73b3aa927a..60af6db0381 100644 --- a/src/HotChocolate/Json/src/Json/JsonWriter.cs +++ b/src/HotChocolate/Json/src/Json/JsonWriter.cs @@ -63,6 +63,24 @@ public JsonWriter( _maxDepth = options.MaxDepth == 0 ? 64 : options.MaxDepth; } + /// + /// Resets the writer so it can be reused with a new buffer, + /// avoiding allocations when the writer is pooled. + /// + /// The new buffer writer to write to. + public void Reset(IBufferWriter writer) + { + ArgumentNullException.ThrowIfNull(writer); + + _writer = writer; + _currentDepth = 0; + _tokenType = default; + _containerTypeStack = 0; + _realWriter = null; + _savedCurrentDepth = 0; + _savedTokenType = default; + } + /// /// Gets the custom behavior when writing JSON using /// the which indicates whether to format the output @@ -77,7 +95,7 @@ public JsonWriter( public JsonNullIgnoreCondition NullIgnoreCondition { get; set; } /// - /// Getswha a value indicating whether null fields should be omitted + /// Gets a value indicating whether null fields should be omitted /// when writing JSON objects. /// public bool IgnoreNullFields