NewtonsoftJsonContent Class

Namespace
Kampute.HttpClient.NewtonsoftJson
Assembly
  • Kampute.HttpClient.NewtonsoftJson.dll

Definition

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

Constructors

NewtonsoftJsonContent(object)

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

Parameters

content object
The object to serialize.

Exceptions

ArgumentNullException
Thrown if content is null.

Properties

Settings

Gets or sets the serializer settings.
public JsonSerializerSettings Settings { get; set; }

Property Value

JsonSerializerSettings
The settings 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.