JsonContent Class

Namespace
Kampute.HttpClient.Json
Assembly
  • Kampute.HttpClient.Json.dll

Definition

Represents application/json content that serializes an object with System.Text.Json when it is sent.
public sealed class JsonContent : HttpContent
Inheritance

Constructors

JsonContent(object)

Initializes a new instance of the JsonContent class.
public JsonContent(object content)

Parameters

content object
The object to serialize.

Exceptions

ArgumentNullException
Thrown if content is null.

Properties

Options

Gets or sets the serializer options.
public JsonSerializerOptions Options { get; set; }

Property Value

JsonSerializerOptions
The options used to serialize the object, or null for the defaults of the serializer.

Methods

SerializeToStreamAsync(Stream, TransportContext)

Writes the object to a stream as JSON.
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)

Parameters

stream Stream
The stream to write to.
context TransportContext
The transport context.

Returns

Task
A task that represents the asynchronous operation.

TryComputeLength(out long)

Attempts to compute the length of the content.
protected override bool TryComputeLength(out long length)

Parameters

length long
When this method returns, contains the length of the content in bytes.

Returns

bool
true if the length could be computed; otherwise, false.

Extension Methods

AsDeflate(this HttpContent, CompressionLevel)Wraps the content in content that compresses it with Deflate as it is sent.
AsGzip(this HttpContent, CompressionLevel)Wraps the content in content that compresses it with GZip as it is sent.
FindCharacterEncoding(this HttpContent)Returns the character encoding named by the charset parameter of the Content-Type header.
IsReusable(this HttpContent)Determines whether the content can be sent more than once, as a retry requires.