Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fo-dicom 5.0 - DicomJson to convert List of DicomDataset to string json #1271

Closed
sylvainb31 opened this issue Nov 22, 2021 · 2 comments
Closed

Comments

@sylvainb31
Copy link

I'm trying to convert a List of DicomDataset to a json string, but I can't find the right method to do so in fo-dicom 5.0

When I was using fo-dicom 4.7, i was using the following :

JsonConvert.SerializeObject(studiesListDataSet, new Dicom.Serialization.JsonDicomConverter());

Expected behavior

To have a method in FellowOakDicom.Serialization.DicomJson to convert a List of DicomDataset to a string json.

Method that should exist : ConvertDicomArrayToJson

Does it already exist and I haven't installed the correct package ?

Actual behavior

Actual methods are : ConvertDicomToJson, ConvertJsonToDicom and ConvertJsonToDicomArray

fo-dicom version and OS/platform

fo-dicom 5.0

@gofal
Copy link
Contributor

gofal commented Nov 23, 2021

You are right, that one overload is missing. It will be included in next release. If you cannot wait so long, you can do meanwhile the following:
The code of ConvertDicomToJson is:

    public static string ConvertDicomToJson(DicomDataset dataset, bool writeTagsAsKeywords = false, bool formatIndented = false)
    {
        var options = new JsonSerializerOptions();
        options.Converters.Add(new DicomJsonConverter(writeTagsAsKeywords: writeTagsAsKeywords));
        options.WriteIndented = formatIndented;
        var conv = JsonSerializer.Serialize(dataset, options);
        return conv;
    }

as you can see here:

public static string ConvertDicomToJson(DicomDataset dataset, bool writeTagsAsKeywords = false, bool formatIndented = false)

Those are all public classes, no private or internal code, so you can copy this method into your project and replace the DicomDataset parameter to a DicomDataset[] array parameter, or a IEnumerable<DicomDataset>. The rest still works the same.

@gofal gofal closed this as completed in f7682af Nov 23, 2021
@sylvainb31
Copy link
Author

Thanks a lot for your answer ! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants