Class DictionaryConverter
- Namespace
- adas_core.Domain.Models.BsonConverters
- Assembly
- adas-core.Domain.dll
Represents a JSON converter that handles serialization and deserialization of dictionary types.
public class DictionaryConverter : JsonConverter
- Inheritance
-
JsonConverterDictionaryConverter
- Inherited Members
-
JsonConverter.CanReadJsonConverter.CanWrite
- Extension Methods
Remarks
Inherits from Newtonsoft.Json.JsonConverter to provide custom conversion logic for dictionary-shaped data.
Methods
CanConvert(Type)
Determines whether the converter can handle the specified type.
Returns true only when objectType is exactly Dictionary<TKey, TValue> with string keys and object values.
public override bool CanConvert(Type objectType)
Parameters
objectTypeTypeThe type to evaluate for converter compatibility.
Returns
- bool
trueif the type is Dictionary<TKey, TValue> of string and object; otherwise,false.
ReadJson(JsonReader, Type, object?, JsonSerializer)
Deserializes a JSON object into a dictionary where each key maps to a strongly-typed value based on the property name. Handles "Steps" and "beacons" as lists of Step and LightBeacon respectively, "cameras" as a list of Camera, "relay" as a Relay instance, and stores any other properties as generic objects, using empty collections or default instances when the source value is null.
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
Parameters
readerJsonReaderThe JSON reader used to read the input token.
objectTypeTypeThe type of the object being deserialized.
existingValueobjectThe existing value of the object being read.
serializerJsonSerializerThe JSON serializer used to deserialize nested values.
Returns
- object
A dictionary containing the JSON properties mapped to their deserialized values.
WriteJson(JsonWriter, object?, JsonSerializer)
Serializes a dictionary of entries to JSON, writing each key-value pair as a JSON property using the provided serializer. Returns immediately when the value is null, leaving the writer untouched.
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
Parameters
writerJsonWriterThe JSON writer that receives the serialized output.
valueobjectThe dictionary to serialize; if null, nothing is written.
serializerJsonSerializerThe serializer used to convert each dictionary value into a JSON token.