YamlDotNet
YamlDotNet copied to clipboard
No setter dictionary property deserialization
I have a yaml file.
---
Name: aaa
Age: 12
Props:
"text/html": a
And I have a class.
public class YamlData
{
public string Name { get; set; }
public int Age { get; set; }
public Dictionary<string, string> Props { get; } = new Dictionary<string, string>();
}
Specially, YamlData.Props
dictionary has only get accessor.
For deserializing,
var deserializerBuilder = new DeserializerBuilder()
.IgnoreUnmatchedProperties()
.Build();
var data = deserializerBuilder.Deserialize<YamlData>(File.ReadAllText("test.yaml"));
data.Props
dictionary count is zero.
if I put the set
on Props
property, It is well.
But I can not change the YamlData.Props
in code.
How to resolve these problem?