Class HttpContentSerializer
An abstract base class for implementers of the IHttpContentSerializer and IHttpContentDeserializer interfaces.
This class takes care of the boilerplate code that should be implemented for these two interfaces. See remarks for details.
Namespace: ReqRest.Serializers
Assembly: ReqRest.dll
Syntax
public abstract class HttpContentSerializer : IHttpContentSerializer, IHttpContentDeserializer
Remarks
The IHttpContentSerializer and IHttpContentDeserializer interfaces document certain behaviors which every implementer should fulfill. This base class already implements said features, leaving you with only having to implement the actual serialization logic in your custom serializer.
These features are already implemented:
Properties
DefaultEncoding
Gets the default Encoding which is passed to
Declaration
protected virtual Encoding DefaultEncoding { get; }
Methods
DeserializeAsync(Nullable<HttpContent>, Type)
Deserializes an object of the specified contentType from
the httpContent.
Declaration
public virtual Task<object? > DeserializeAsync(HttpContent? httpContent, Type contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| Nullable<HttpContent> | httpContent | An HttpContent instance from which the content should be serialized. This can be null. |
| Type | contentType | The target type of the object which is supposed to be deserialized. |
Returns
| Type | Description |
|---|---|
| Task<Nullable<Object>> | An object of type |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| HttpContentSerializationException | Deserializing the content failed. |
DeserializeCore(HttpContent, Type)
Called by contentType from
the httpContent.
Declaration
protected abstract Task<object? > DeserializeCore(HttpContent httpContent, Type contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpContent | httpContent | An HttpContent instance from which the content should be serialized. |
| Type | contentType | The target type of the object which is supposed to be deserialized. |
Returns
| Type | Description |
|---|---|
| Task<Nullable<Object>> | An object of type |
Serialize(Nullable<Object>, Nullable<Encoding>)
Serializes the specified content into a new
HttpContent instance.
Declaration
public virtual HttpContent? Serialize(object? content, Encoding? encoding)
Parameters
| Type | Name | Description |
|---|---|---|
| Nullable<Object> | content | The object to be serialized into a new HttpContent instance. This can be null. |
| Nullable<Encoding> | encoding | An optional encoding to be used by the serializer if it serializes the |
Returns
| Type | Description |
|---|---|
| Nullable<HttpContent> | A new HttpContent instance which holds the serialized |
Exceptions
| Type | Condition |
|---|---|
| HttpContentSerializationException | Serializing the |
SerializeCore(Nullable<Object>, Encoding)
Called by content into a new
HttpContent instance.
Declaration
protected abstract HttpContent? SerializeCore(object? content, Encoding encoding)
Parameters
| Type | Name | Description |
|---|---|---|
| Nullable<Object> | content | The object to be serialized into a new HttpContent instance. |
| Encoding | encoding | An optional encoding to be used by the serializer if it serializes the |
Returns
| Type | Description |
|---|---|
| Nullable<HttpContent> | A new HttpContent instance which holds the serialized |