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
supportedMediaTypesstring[]An array of media types that this deserializer supports.
Exceptions
- ArgumentNullException
Thrown if
supportedMediaTypesis 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
mediaTypestringThe media type of the content.
modelTypeTypeThe 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
contentHttpContentThe HttpContent to read from.
modelTypeTypeThe type of the object to be deserialized.
cancellationTokenCancellationTokenA 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
contentormodelTypeis null.
GetSupportedMediaTypes(Type)
Retrieves a collection of supported media types for a specific model type.
public virtual IEnumerable<string> GetSupportedMediaTypes(Type modelType)
Parameters
modelTypeTypeThe 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.