I have the json below
"Payload": {
"AdditionalProperties": [
{
"Key": "MyKey1",
"Value": "Value"
},
{
"Key": "MyKey2",
"Value": "Value"
}
]
}
By default this can be deserialized into an object with AdditionalProperties being deserialized into a List where AdditionalProperty just has 2 properties Key and Value - both strings
How can I get the json above to deserialize into a Dictionary<string, string> automatically?
At the moment I have had to create a separate property which isnt very nice
public List<AdditionalProperty> AdditionalProperties { get; set; }
public Dictionary<string, string> AdditionalPropertiesDictionary
{
get
{
return _additionalPropertiesDictionary ??= AdditionalProperties.ToDictionary(x => x.Key, x => x.Value);
}
set => _additionalPropertiesDictionary = value;
}
Paul