Skip to content
Documentation

Serializer<TData,TParameters> Class

Provides a base implementation for custom serializers (ISerializer).

public abstract class Serializer<TData,TParameters> : HAKOM.Serialization.Core.Net.Api.ISerializer, HAKOM.Serialization.Core.Net.Api.ISerializer<TData>, HAKOM.DependencyInjection.Core.Net.Api.IRequiresConfiguration
where TParameters : HAKOM.Serialization.Core.Net.Api.Parametrization.ISerializationParameters

TData

The type of data that this serializer serializes/deserializes.

TParameters

The type of parameters (ISerializationParameters) that this serializer uses. These are parsed from the media type it is configured with using the Configure(MediaTypeHeaderValue) method.

Inheritance System.Object 🡒 Serializer<TData,TParameters>

Derived
↳ JsonSerializer<TData>
↳ XmlSerializer<TData>

Implements ISerializer, HAKOM.Serialization.Core.Net.Api.ISerializer<TData>, IRequiresConfiguration

Serializer(ISerializationParametersFactory<TParameters>) Constructor

Section titled “Serializer(ISerializationParametersFactory<TParameters>) Constructor”

Instantiates the serializer.

protected Serializer(HAKOM.Serialization.Core.Net.Api.Parametrization.ISerializationParametersFactory<TParameters> parametersFactory);

parametersFactory HAKOM.Serialization.Core.Net.Api.Parametrization.ISerializationParametersFactory<TParameters>

The factory that should be used to parse the serializers media type into an object of type TParameters.

Serializer<TData,TParameters>.DefaultSubType Property

Section titled “Serializer<TData,TParameters>.DefaultSubType Property”

Specifies which type should be used if the serializer is initialized with a wildcard type. (i.e. if Configure(MediaTypeHeaderValue) is called with “application/*”, the “*” is then replaced with DefaultSubType so that ParsedMediaType would become, for example: “application/xml”.).

protected abstract string DefaultSubType { protected get; }

System.String

Serializer<TData,TParameters>.DefaultType Property

Section titled “Serializer<TData,TParameters>.DefaultType Property”

Specifies which type should be used if the serializer is initialized with a wildcard type. (i.e. if Configure(MediaTypeHeaderValue) is called with “*/json”, the “*” is then replaced with DefaultType so that ParsedMediaType would become, for example: “application/json”.).

protected abstract string DefaultType { protected get; }

System.String

Serializer<TData,TParameters>.OriginalMediaType Property

Section titled “Serializer<TData,TParameters>.OriginalMediaType Property”

The media type this serializer was initially configured with (see the Configure(MediaTypeHeaderValue) method). May include wildcards etc. i.e. “*/*+json”. Must be set by Configure(MediaTypeHeaderValue).

public System.Net.Http.Headers.MediaTypeHeaderValue OriginalMediaType { get; }

Implements OriginalMediaType

System.Net.Http.Headers.MediaTypeHeaderValue

Serializer<TData,TParameters>.Parameters Property

Section titled “Serializer<TData,TParameters>.Parameters Property”

Provides access to the parameters parsed from the media type upon.

This property is set during initialization (Configure(MediaTypeHeaderValue)).

protected TParameters Parameters { protected get; }

TParameters

Serializer<TData,TParameters>.ParsedMediaType Property

Section titled “Serializer<TData,TParameters>.ParsedMediaType Property”

The actual media type that’s used by the serializer. For example, assuming Configure(MediaTypeHeaderValue) is called with “*/*+json” this serializer may interpret this as “application/hal+json;charset=utf-8;indentation=true”. This property should then contain that final media type used.

public System.Net.Http.Headers.MediaTypeHeaderValue ParsedMediaType { get; }

Implements ParsedMediaType

System.Net.Http.Headers.MediaTypeHeaderValue

Serializer<TData,TParameters>.Configure(MediaTypeHeaderValue) Method

Section titled “Serializer<TData,TParameters>.Configure(MediaTypeHeaderValue) Method”

Configures this instance with a specific media type (i.e. “application/json”, “text/html”, etc.). Implementations must use this method to interpret media type parameters, set default values, etc. This method must also set OriginalMediaType to the value of mediaType and ParsedMediaType to the media type containing no wildcards and any default values for parameters used.

public virtual void Configure(System.Net.Http.Headers.MediaTypeHeaderValue mediaType);

mediaType System.Net.Http.Headers.MediaTypeHeaderValue

The media type for this serializer to use.

Implements Configure(MediaTypeHeaderValue)

Serializer<TData,TParameters>.DeserializationFailedException(string) Method

Section titled “Serializer<TData,TParameters>.DeserializationFailedException(string) Method”

Creates a new DeserializationFailedException with the specified message.

protected HAKOM.Serialization.Core.Net.Api.Exceptions.DeserializationFailedException DeserializationFailedException(string message);

message System.String

The error message describing the deserialization failure.

DeserializationFailedException
A new DeserializationFailedException instance.

Serializer<TData,TParameters>.DeserializationFailedException(string, Exception) Method

Section titled “Serializer<TData,TParameters>.DeserializationFailedException(string, Exception) Method”

Creates a new DeserializationFailedException with the specified message and innerException.

protected HAKOM.Serialization.Core.Net.Api.Exceptions.DeserializationFailedException DeserializationFailedException(string message, System.Exception innerException);

message System.String

The error message describing the deserialization failure.

innerException System.Exception

The exception that caused the deserialization failure.

DeserializationFailedException
A new DeserializationFailedException instance.

Serializer<TData,TParameters>.Deserialize(Stream, CancellationToken) Method

Section titled “Serializer<TData,TParameters>.Deserialize(Stream, CancellationToken) Method”

Attempts to deserialize an object of type TData from the given inputStream.

public abstract System.Threading.Tasks.Task<TData?> Deserialize(System.IO.Stream inputStream, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

inputStream System.IO.Stream

The System.IO.Stream to deserialize from.

cancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to signal the operation that it should be canceled.

Implements Deserialize(Stream, CancellationToken)

System.Threading.Tasks.Task<TData>
A task that completes when deserialization is done.

Serializer<TData,TParameters>.DeserializeAsObject(Stream, CancellationToken) Method

Section titled “Serializer<TData,TParameters>.DeserializeAsObject(Stream, CancellationToken) Method”

Asynchronously deserializes an object from the given inputStream.

public virtual System.Threading.Tasks.Task<object?> DeserializeAsObject(System.IO.Stream inputStream, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

inputStream System.IO.Stream

The System.IO.Stream to read data from.

cancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to signal the serializer to attempt cancelling the operation.

Implements DeserializeAsObject(Stream, CancellationToken)

System.Threading.Tasks.Task<System.Object>
A System.Threading.Tasks.Task<> that completes when the object has been successfully read from the inputStream.

Serializer<TData,TParameters>.ProcessMediaType() Method

Section titled “Serializer<TData,TParameters>.ProcessMediaType() Method”

Processes OriginalMediaType and sets ParsedMediaType based on DefaultType, DefaultSubType and the media type parameters parsed using the ISerializationParametersFactory<TParameters> injected into the constructor Serializer(ISerializationParametersFactory<TParameters>).

protected virtual System.Net.Http.Headers.MediaTypeHeaderValue ProcessMediaType();

System.Net.Http.Headers.MediaTypeHeaderValue

Serializer<TData,TParameters>.SerializationFailedException(string) Method

Section titled “Serializer<TData,TParameters>.SerializationFailedException(string) Method”

Creates a new SerializationFailedException with the specified message.

protected HAKOM.Serialization.Core.Net.Api.Exceptions.SerializationFailedException SerializationFailedException(string message);

message System.String

The error message describing the serialization failure.

SerializationFailedException
A new SerializationFailedException instance.

Serializer<TData,TParameters>.SerializationFailedException(string, Exception) Method

Section titled “Serializer<TData,TParameters>.SerializationFailedException(string, Exception) Method”

Creates a new SerializationFailedException with the specified message and innerException.

protected HAKOM.Serialization.Core.Net.Api.Exceptions.SerializationFailedException SerializationFailedException(string message, System.Exception innerException);

message System.String

The error message describing the serialization failure.

innerException System.Exception

The exception that caused the serialization failure.

SerializationFailedException
A new SerializationFailedException instance.

Serializer<TData,TParameters>.Serialize(TData, Stream, CancellationToken) Method

Section titled “Serializer<TData,TParameters>.Serialize(TData, Stream, CancellationToken) Method”

Serializes the given instance of TData to the outputStream.

public abstract System.Threading.Tasks.Task Serialize(TData data, System.IO.Stream outputStream, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

data TData

The object to serialize.

outputStream System.IO.Stream

The System.IO.Stream to serialize to.

cancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to signal the operation that it should be canceled.

Implements Serialize(TData, Stream, CancellationToken)

System.Threading.Tasks.Task
A task that completes when data has been serialized.

Serializer<TData,TParameters>.SerializeObject(object, Stream, CancellationToken) Method

Section titled “Serializer<TData,TParameters>.SerializeObject(object, Stream, CancellationToken) Method”

Asynchronously serializes data into the outputStream.

public virtual System.Threading.Tasks.Task SerializeObject(object? data, System.IO.Stream outputStream, System.Threading.CancellationToken cancellationToken=default(System.Threading.CancellationToken));

data System.Object

The object to serialize.

outputStream System.IO.Stream

The stream to serialize to.

cancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to signal the serializer to attempt cancelling the operation.

Implements SerializeObject(object, Stream, CancellationToken)

System.Threading.Tasks.Task
Returns a System.Threading.Tasks.Task that completes once all of data has been written to outputStream.

© 2026 Volue.Version v0.6.38017 November 2026