Class DictionarySerializer<TKey, TValue>
Type serializer for Dictionary<TKey, TValue> collections. The serialization format differs based on the key type:
-
When
TKeyis string, the dictionary is written as a JSON object where each key becomes a property name and each value becomes the corresponding property value. -
When
TKeyis any other type, the dictionary is written as a JSON array of{"k": key, "v": value}objects, preserving type fidelity for complex key types.
A null reference is serialized as a null token.
Inherited Members
Namespace: Scylla.Core.Util.Serialization
Assembly: ScyllaCore.dll
Syntax
public sealed class DictionarySerializer<TKey, TValue> : TypeSerializerBase<Dictionary<TKey, TValue>>, ITypeSerializer<Dictionary<TKey, TValue>>, ITypeSerializer
Type Parameters
| Name | Description |
|---|---|
| TKey | The key type of the dictionary. When |
| TValue | The value type of the dictionary. |
Remarks
Comma handling between JSON array elements is delegated to SkipComma() when the active reader is a ScyllaJSONReader.
Constructors
DictionarySerializer(ITypeSerializer, ITypeSerializer)
Creates a dictionary serializer with the specified key and value serializers.
Declaration
public DictionarySerializer(ITypeSerializer keySerializer, ITypeSerializer valueSerializer)
Parameters
| Type | Name | Description |
|---|---|---|
| ITypeSerializer | keySerializer | The non-generic serializer to use for every dictionary key, or |
| ITypeSerializer | valueSerializer | The non-generic serializer to use for every dictionary value, or |
Methods
Read(IScyllaReader, ISerializationContext)
Reads a Dictionary<TKey, TValue> from the reader.
Returns null when the next token is a null literal. Chooses the JSON-object
path when TKey is string, or the array-of-pairs path
for all other key types.
Declaration
public override Dictionary<TKey, TValue> Read(IScyllaReader reader, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| IScyllaReader | reader | The reader positioned at the start of an object, array, or null token.
Never |
| ISerializationContext | context | The active serialization context. Never |
Returns
| Type | Description |
|---|---|
| Dictionary<TKey, TValue> | The deserialized dictionary, or |
Overrides
Write(Dictionary<TKey, TValue>, IScyllaWriter, ISerializationContext)
Writes a Dictionary<TKey, TValue> to the output.
Emits a null token if value is null. When
TKey is string, emits a JSON object; otherwise emits a
JSON array of {"k":…, "v":…} entry objects.
Declaration
public override void Write(Dictionary<TKey, TValue> value, IScyllaWriter writer, ISerializationContext context)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<TKey, TValue> | value | The dictionary to serialize, or |
| IScyllaWriter | writer | The writer that receives the serialized output. Never |
| ISerializationContext | context | The active serialization context. Never |