I am trying to make sense of the documentation:
My goal is simply to load DICOM/JSON using System.Text.Json.JsonSerializer (dotnet 5.0). The steps are easy from C# to JSON:
private class DataElement<T>
{
public string vr { get; set; }
public List<T> Value { get; set; }
}
[...]
var dataset = new Dictionary<string, object>();
dataset.Add("00100021", new DataElement<string>() { vr = "LO", Value = new List<string>(1) { "Hospital A" }});
dataset.Add("00201206", new DataElement<int>() { vr = "IS", Value = new List<int>(1) { 4 } });
dataset.Add("00101030", new DataElement<double>() { vr = "DS", Value = new List<double>(1) { 72.5 } });
string jsonString = JsonSerializer.Serialize(dataset, serializeOptions);
File.WriteAllBytes("ds.json", Encoding.UTF8.GetBytes(jsonString));
But doing it the other way around seems much more complex.
How should I implement the custom converters for those 3 possible generics (string, int or double) ?
