I have a json file that looks like this:
{
"tags": {
"t1": {
"description": "bar"
},
"t2": {
"description": {
"$ref": "./t2.md"
}
}
}
}
and I would like to deserialize it with Json.NET like this:
var baz = JsonConvert.DeserializeObject<Baz>(File.ReadAllText(@"baz.json"));
//...
internal class Baz
{
[JsonProperty("tags")]
internal Tags Tags;
}
internal class Tags: Dictionary<string, Tag>
{
}
internal class Tag
{
[JsonProperty("description")]
internal Description Description;
}
internal class Description // FIXME: can be string, Dictionary or List
{
}
How can I define the Description class, that can be either a string or a Dictionary<string, string>? I have tried inheriting an abstract method, but the deserializer always returned null.
{"$ref": "..."}object.obj["$ref"]in the second link you have posted. Please add an answer, so that I can accept it.