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
Methods
CanReadType(Type)
Queries whether this MediaTypeFormatter can deserializean object of the specified type.
public override bool CanReadType(Type type)
Parameters
typeTypeThe 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
typeTypeThe 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
typeTypeThe type of the object to deserialize.
readStreamStreamThe Stream to read.
contentHttpContentThe HttpContent, if available. It may be null.
formatterLoggerIFormatterLoggerThe IFormatterLogger to log events to.
Returns
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
typeTypeThe type of the object to deserialize.
readStreamStreamThe Stream to read.
contentHttpContentThe HttpContent, if available. It may be null.
formatterLoggerIFormatterLoggerThe IFormatterLogger to log events to.
cancellationTokenCancellationTokenThe token to cancel the operation.
Returns
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
typeTypeThe type of the object to write.
valueobjectThe object value to write. It may be null.
writeStreamStreamThe Stream to which to write.
contentHttpContentThe HttpContent if available. It may be null.
transportContextTransportContextThe TransportContext if available. It may be null.
Returns
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
typeTypeThe type of the object to write.
valueobjectThe object value to write. It may be null.
writeStreamStreamThe Stream to which to write.
contentHttpContentThe HttpContent if available. It may be null.
transportContextTransportContextThe TransportContext if available. It may be null.
cancellationTokenCancellationTokenThe token to cancel the operation.
Returns
Exceptions
- NotSupportedException
Derived types need to support writing.