Table of Contents

Class SystemTextJsonSerializer

Namespace
TypedRest.Serializers
Assembly
TypedRest.SystemTextJson.dll

Handles serializing/deserializing from/to JSON using System.Text.Json. Uses camel-case naming and does not serialize null by default.

NuGet: TypedRest.SystemTextJson

public class SystemTextJsonSerializer : MediaTypeFormatter
Inheritance
SystemTextJsonSerializer
Inherited Members

Constructors

SystemTextJsonSerializer()

public SystemTextJsonSerializer()

Properties

Options

Serializer options.

public JsonSerializerOptions Options { get; }

Property Value

JsonSerializerOptions

Methods

CanReadType(Type)

Queries whether this MediaTypeFormatter can deserializean object of the specified type.

public override bool CanReadType(Type type)

Parameters

type Type

The type to deserialize.

Returns

bool

true if the MediaTypeFormatter can deserialize the type; otherwise, false.

CanWriteType(Type)

Queries whether this MediaTypeFormatter can serializean object of the specified type.

public override bool CanWriteType(Type type)

Parameters

type Type

The type to serialize.

Returns

bool

true if the MediaTypeFormatter can serialize the type; otherwise, false.

ReadFromStreamAsync(Type, Stream, HttpContent, IFormatterLogger)

Asynchronously deserializes an object of the specified type.

public override Task<object?> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)

Parameters

type Type

The type of the object to deserialize.

readStream Stream

The Stream to read.

content HttpContent

The HttpContent, if available. It may be null.

formatterLogger IFormatterLogger

The IFormatterLogger to log events to.

Returns

Task<object>

A Task whose result will be an object of the given type.

Exceptions

NotSupportedException

Derived types need to support reading.

ReadFromStreamAsync(Type, Stream, HttpContent, IFormatterLogger, CancellationToken)

Asynchronously deserializes an object of the specified type.

public override Task<object?> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken cancellationToken)

Parameters

type Type

The type of the object to deserialize.

readStream Stream

The Stream to read.

content HttpContent

The HttpContent, if available. It may be null.

formatterLogger IFormatterLogger

The IFormatterLogger to log events to.

cancellationToken CancellationToken

The token to cancel the operation.

Returns

Task<object>

A Task whose result will be an object of the given type.

WriteToStreamAsync(Type, object, Stream, HttpContent, TransportContext)

Asynchronously writes an object of the specified type.

public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext)

Parameters

type Type

The type of the object to write.

value object

The object value to write. It may be null.

writeStream Stream

The Stream to which to write.

content HttpContent

The HttpContent if available. It may be null.

transportContext TransportContext

The TransportContext if available. It may be null.

Returns

Task

A Task that will perform the write.

Exceptions

NotSupportedException

Derived types need to support writing.

WriteToStreamAsync(Type, object, Stream, HttpContent, TransportContext, CancellationToken)

Asynchronously writes an object of the specified type.

public override Task WriteToStreamAsync(Type type, object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)

Parameters

type Type

The type of the object to write.

value object

The object value to write. It may be null.

writeStream Stream

The Stream to which to write.

content HttpContent

The HttpContent if available. It may be null.

transportContext TransportContext

The TransportContext if available. It may be null.

cancellationToken CancellationToken

The token to cancel the operation.

Returns

Task

A Task that will perform the write.

Exceptions

NotSupportedException

Derived types need to support writing.