8000 DicomJsonConverter throws for non-DicomElements · Issue #1792 · fo-dicom/fo-dicom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
8000 Skip to content
DicomJsonConverter throws for non-DicomElements #1792
Closed
@edespong

Description

@edespong

Describe the bug
Trying to serialize a DICOM header that contains DicomItems 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0