Table of Contents

Class HttpContentDeserializer

Namespace
Kampute.HttpClient.Content.Abstracts
Assembly
Kampute.HttpClient.dll

Provides functionality for deserializing content from HTTP responses into objects.

public abstract class HttpContentDeserializer : IHttpContentDeserializer
Inheritance
HttpContentDeserializer
Implements
Derived
Inherited Members

Constructors

HttpContentDeserializer(params string[])

Initializes a new instance of the HttpContentDeserializer class with specified supported media types.

protected HttpContentDeserializer(params string[] supportedMediaTypes)

Parameters

supportedMediaTypes string[]

An array of media types that this deserializer supports.

Exceptions

ArgumentNullException

Thrown if supportedMediaTypes is null.

Properties

SupportedMediaTypes

Gets the collection of media types that this deserializer supports.

public IReadOnlyCollection<string> SupportedMediaTypes { get; }

Property Value

IReadOnlyCollection<string>

The read-only collection of media types that this deserializer can handle.

Methods

CanDeserialize(string, Type)

Determines whether this deserializer can handle data of a specific media type and deserialize it into the specified model type.

public virtual bool CanDeserialize(string mediaType, Type modelType)

Parameters

mediaType string

The media type of the content.

modelType Type

The target model type for deserialization.

Returns

bool

true if the deserializer supports the media type and the model type is not null; otherwise, false.

DeserializeAsync(HttpContent, Type, CancellationToken)

Asynchronously reads and deserializes an object from the provided HttpContent.

public abstract Task<object?> DeserializeAsync(HttpContent content, Type modelType, CancellationToken cancellationToken = default)

Parameters

content HttpContent

The HttpContent to read from.

modelType Type

The type of the object to be deserialized.

cancellationToken CancellationToken

A token for canceling the read operation (optional).

Returns

Task<object>

A task representing the asynchronous read operation, which upon completion contains the deserialized object, or null if deserialization fails.

Exceptions

ArgumentNullException

Thrown if either content or modelType is null.

GetSupportedMediaTypes(Type)

Retrieves a collection of supported media types for a specific model type.

public virtual IEnumerable<string> GetSupportedMediaTypes(Type modelType)

Parameters

modelType Type

The type of the model for which to retrieve supported media types.

Returns

IEnumerable<string>

An enumerable of strings representing the media types supported for the specified model type.