ReqRest
Show / Hide Table of Contents

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.

Inheritance
Object
HttpContentSerializer
JsonHttpContentSerializer
Implements
IHttpContentSerializer
IHttpContentDeserializer
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 if no encoding was provided by the user. If not overridden, this is UTF8.

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 contentType.

Exceptions
Type Condition
ArgumentNullException
  • contentType
HttpContentSerializationException

Deserializing the content failed.

DeserializeCore(HttpContent, Type)

Called by . This method should perform the actual deserialization logic, i.e. it should deserialize an object of the specified 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 contentType.

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 content to an HttpContent which requires one. If null, a default encoding is used.

Returns
Type Description
Nullable<HttpContent>

A new HttpContent instance which holds the serialized content or null.

Exceptions
Type Condition
HttpContentSerializationException

Serializing the content failed.

SerializeCore(Nullable<Object>, Encoding)

Called by . This method should perform the actual serialization logic, i.e. it should serialize the specified 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 content to an HttpContent which requires one.

Returns
Type Description
Nullable<HttpContent>

A new HttpContent instance which holds the serialized content or null.

Implements

IHttpContentSerializer
IHttpContentDeserializer

Extension Methods

HttpContentDeserializerExtensions.DeserializeAsync<T>(IHttpContentDeserializer, Nullable<HttpContent>)
Back to top Copyright © 2019 ReqRest - Generated with DocFX - Material Theme made by Oscar Vásquez - Impressum (Imprint)