Closed
Description
Describe the bug
Trying to serialize a DICOM header that contains DicomItem
s that are not DicomElement
. This results in exceptions.
To Reproduce
Minimal program:
using FellowOakDicom;
using FellowOakDicom.Serialization;
using JsonSerializer = System.Text.Json.JsonSerializer;
DicomDataset ds = new DicomDataset(new DicomOtherByteFragment(DicomTag.PixelData));
var jsonOptions = new JsonSerializerOptions {
WriteIndented = true,
Converters = { new DicomJsonConverter() }
};
string jsonArray = JsonSerializer.Serialize(ds, jsonOptions);
Expected behavior
To handle serialization gracefully, according to type. There are probably variations based on the subclass of DicomItem.
Basically, the code in the serializer is:
private void WriteJsonDicomItem(Utf8JsonWriter writer, DicomItem item, JsonSerializerOptions options) {
writer.WriteStartObject();
writer.WriteString("vr", item.ValueRepresentation.Code);
switch (item.ValueRepresentation.Code) {
case "PN":
......
case "OB":
case "OD":
case "OF":
case "OL":
case "OV":
case "OW":
case "UN":
WriteJsonOther(writer, (DicomElement)item); <---- throws here
break;
case "FL":
There is no check anywhere that the item
is actually a DicomElement.
Environment
fo-dicom 5.1.2