I have the following JSON payload:
{
"id": 1,
"foo": "bar",
"bar": "foo",
"attr_1": ["foo", "bar"],
"attr_2": ["foo2", "bar2"]
}
I also have the following CLR object:
public class Obj
{
public int Id { get; set; }
public string Foo { get; set; }
public string Bar { get; set; }
[JsonExtensionData]
public IDictionary<string, string[]> Properties { get; set; }
}
If I try to deserialize it, it fails:
using (FileStream file = File.Open(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "file.txt"), FileMode.Open))
using (StreamReader reader = new StreamReader(file))
{
Obj foo = JsonConvert.DeserializeObject<Obj>(reader.ReadToEnd());
}
There is already an answer to a similar question. However, it's not a solution to read and write each field one by one. What is the best way for me to deserialize leftover fields into IDictionary<string, string[]>
?