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
type
TypeThe 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
TypeThe 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
TypeThe type of the object to deserialize.
readStream
StreamThe Stream to read.
content
HttpContentThe HttpContent, if available. It may be null.
formatterLogger
IFormatterLoggerThe 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
type
TypeThe type of the object to deserialize.
readStream
StreamThe Stream to read.
content
HttpContentThe HttpContent, if available. It may be null.
formatterLogger
IFormatterLoggerThe IFormatterLogger to log events to.
cancellationToken
CancellationTokenThe 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
type
TypeThe type of the object to write.
value
objectThe object value to write. It may be null.
writeStream
StreamThe Stream to which to write.
content
HttpContentThe HttpContent if available. It may be null.
transportContext
TransportContextThe 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
type
TypeThe type of the object to write.
value
objectThe object value to write. It may be null.
writeStream
StreamThe Stream to which to write.
content
HttpContentThe HttpContent if available. It may be null.
transportContext
TransportContextThe TransportContext if available. It may be null.
cancellationToken
CancellationTokenThe token to cancel the operation.
Returns
Exceptions
- NotSupportedException
Derived types need to support writing.