Table of Contents

Class PolyTypeJsonFormatter

Namespace
StreamJsonRpc
Assembly
StreamJsonRpc.dll

A formatter that emits UTF-8 encoded JSON where user data should be serializable via the JsonSerializer. This formatter is NativeAOT ready and relies on PolyType.

public class PolyTypeJsonFormatter : FormatterBase, IJsonRpcFormatterState, IDisposable, IJsonRpcMessageTextFormatter, IJsonRpcMessageFormatter, IJsonRpcInstanceContainer, IJsonRpcMessageFactory, IJsonRpcFormatterTracingCallbacks
Inheritance
PolyTypeJsonFormatter
Implements
Inherited Members

Constructors

PolyTypeJsonFormatter()

Initializes a new instance of the PolyTypeJsonFormatter class.

public PolyTypeJsonFormatter()

Properties

Encoding

Gets or sets the encoding used for serialization for methods that do not take an explicit Encoding.

public Encoding Encoding { get; set; }

Property Value

Encoding

Never null.

Exceptions

ArgumentNullException

Thrown at an attempt to set the value to null.

JsonSerializerOptions

Gets or sets the options to use when serializing and deserializing JSON containing user data.

public JsonSerializerOptions JsonSerializerOptions { get; set; }

Property Value

JsonSerializerOptions

TypeShapeProvider

Gets the shape provider for user data types.

public required ITypeShapeProvider TypeShapeProvider { get; init; }

Property Value

ITypeShapeProvider

Methods

Deserialize(ReadOnlySequence<byte>)

Deserializes a JsonRpcMessage.

public JsonRpcMessage Deserialize(ReadOnlySequence<byte> contentBuffer)

Parameters

contentBuffer ReadOnlySequence<byte>

A sequence of bytes to deserialize.

Returns

JsonRpcMessage

The deserialized JsonRpcMessage.

Deserialize(ReadOnlySequence<byte>, Encoding)

Deserializes a sequence of bytes to a JsonRpcMessage.

public JsonRpcMessage Deserialize(ReadOnlySequence<byte> contentBuffer, Encoding encoding)

Parameters

contentBuffer ReadOnlySequence<byte>

The bytes to deserialize.

encoding Encoding

The encoding to read the bytes in contentBuffer with. Must not be null.

Returns

JsonRpcMessage

The deserialized message.

GetJsonText(JsonRpcMessage)

Gets a JSON representation for a given message for tracing purposes.

public object GetJsonText(JsonRpcMessage message)

Parameters

message JsonRpcMessage

The message to be traced.

Returns

object

Any object whose ToString() method will produce a human-readable JSON string, suitable for tracing.

RegisterGenericType<T>()

Registers a type that may be used as a generic type argument for some generic value to be serialized, such as IProgress<T> or IAsyncEnumerable<T>.

public void RegisterGenericType<T>()

Type Parameters

T

The type argument to some generic type.

Serialize(IBufferWriter<byte>, JsonRpcMessage)

Serializes a JsonRpcMessage.

public void Serialize(IBufferWriter<byte> bufferWriter, JsonRpcMessage message)

Parameters

bufferWriter IBufferWriter<byte>

The receiver of the serialized bytes.

message JsonRpcMessage

The message to serialize.