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
- object
- HttpContent
- JsonContent
Constructors
JsonContent(object)
Initializes a new instance of the JsonContent class.
public JsonContent(object content)Parameters
contentobject- The object to serialize.
Exceptions
- ArgumentNullException
- Thrown if
contentisnull.
Properties
Options
Gets or sets the serializer options.
public JsonSerializerOptions Options { get; set; }Property Value
- JsonSerializerOptions
- The options used to serialize the object, or
nullfor 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
streamStream- The stream to write to.
contextTransportContext- 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
lengthlong- When this method returns, contains the length of the content in bytes.
Returns
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. |
