HttpContentDeserializer Class
- Namespace
- Kampute.HttpClient.Content.Abstracts
- Assembly
- Kampute.HttpClient.dll
Definition
Provides functionality for deserializing content from HTTP responses into objects.
public abstract class HttpContentDeserializer : IHttpContentDeserializer- Inheritance
- object
- HttpContentDeserializer
- Implements
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
supportedMediaTypesisnull.
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
mediaTypestring- The media type of the content.
modelTypeType- The target model type for deserialization.
Returns
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
contentHttpContent- The HttpContent to read from.
modelTypeType- The type of the object to be deserialized.
cancellationTokenCancellationToken optional- 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
nullif deserialization fails.
Exceptions
- ArgumentNullException
- Thrown if either
contentormodelTypeisnull.
GetSupportedMediaTypes(Type)
Retrieves a collection of supported media types for a specific model type.
public virtual IEnumerable<string> GetSupportedMediaTypes(Type modelType)Parameters
modelTypeType- 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.
