YamlDotNet icon indicating copy to clipboard operation
YamlDotNet copied to clipboard

No setter dictionary property deserialization

Open powerumc opened this issue 5 years ago • 0 comments

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?

powerumc avatar Dec 04 '19 08:12 powerumc