QaaS.Framework.Serialization¶
TL;DR — QaaS.Framework.Serialization provides shared serializers and deserializers used by Framework and SDK packages.
QaaS.Framework.Serialization is the Framework solution's serializer and deserializer package. It is a standalone package that other QaaS packages reference, including QaaS.Framework.SDK. The package contains the configuration objects that choose a format, the factories that create the right runtime implementation, and the concrete serializers and deserializers for each supported format.
What this project contains¶
Format selection and configuration¶
The package exposes four central configuration types:
SerializationType.csSerializeConfig.csDeserializeConfig.csSpecificTypeConfig.cs
SerializationType is the format enum used across the package. SerializeConfig and DeserializeConfig describe how a caller wants serialization or deserialization to happen. SpecificTypeConfig stores the type metadata needed when deserialization must reconstruct a specific runtime type.
Factory layer¶
The runtime dispatch layer is implemented in:
SerializerFactory.csDeserializerFactory.cs
These factories translate the selected SerializationType into a concrete serializer or deserializer implementation.
Factory usage¶
using QaaS.Framework.Serialization;
var serializer = SerializerFactory.BuildSerializer(SerializationType.Json)!;
var deserializer = DeserializerFactory.BuildDeserializer(SerializationType.Json)!;
byte[]? payload = serializer.Serialize(order);
Order? restored = (Order?)deserializer.Deserialize(payload, typeof(Order));
order and Order are application-defined. ISerializer.Serialize(object?) returns byte[]?, and IDeserializer.Deserialize(byte[]?, Type?) returns object?. Both factories return null for a null format, so callers must handle the no-conversion case explicitly.
The convenience facade and serializer extension methods were reverted in Framework PR #48. Use the factories above; see Casting & Serializing Data for runtime casts and explicit payload conversion.
Concrete serializers¶
The Serializers folder currently contains:
Binary.csJson.csMessagePack.csXml.csXmlElement.csYaml.csProtobufMessage.cs
Concrete deserializers¶
The Deserializers folder contains the matching format implementations:
Binary.csJson.csMessagePack.csXml.csXmlElement.csYaml.csProtobufMessage.cs
Supported formats¶
The current package supports these serialization formats:
BinaryJsonMessagePackXmlXmlElementYamlProtobufMessage
The current enum and implementation name is ProtobufMessage, not Protobuf.
Current behavior¶
The current implementation includes several format-specific behaviors that are worth calling out:
- both factories return
nullfor a null format and throwArgumentOutOfRangeExceptionfor unsupported enum values SpecificTypeConfigresolves a runtime type from assembly and type-name metadataSpecificTypeConfigcan backfill the assembly name from the entry assembly when the configuration omits it- binary deserialization uses
BinaryFormatter, ignores the requested target type, and reconstructs the payload's stored runtime type - protobuf-message deserialization also requires an explicit target type
- XML deserialization returns
XDocumentorXElementrather than typed POCOs, even when a target type is supplied - several deserializers return
nullfornullpayloads instead of throwing - YAML deserialization contains a special case for empty payloads when the requested type is
string
This package is used heavily by the SDK for session and communication serialization, but it remains a separate package because the serialization layer is intentionally reusable outside of the SDK's higher-level object surface.
Main source areas¶
The most important files and folders are:
SerializationType.csSerializeConfig.csDeserializeConfig.csSpecificTypeConfig.csSerializerFactory.csDeserializerFactory.csSerializers/Deserializers/
Companion tests¶
QaaS.Framework.Serialization.Tests is the sibling test project for this package.
The current tests cover:
- factory dispatch for every supported format
- round-trip serialization for Binary, Json, MessagePack, Xml, XmlElement, Yaml, and ProtobufMessage
SpecificTypeConfigruntime-type resolution- invalid enum handling
- explicit target-type requirements for ProtobufMessage deserialization
- binary deserialization without a target type and ignoring a requested type hint
- null and empty payload behavior
Representative test files include:
SerializationBehaviorTests.csSerializationEdgeCaseTests.cs