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

JSONWriter creates invalid json DataFragment element #254

Closed
lexxoff opened this issue Mar 21, 2018 · 0 comments
Closed

JSONWriter creates invalid json DataFragment element #254

lexxoff opened this issue Mar 21, 2018 · 0 comments

Comments

@lexxoff
Copy link

lexxoff commented Mar 21, 2018

Given a dcm file with Pixel data split into two items:

2284: (7FE0,0010) OB #-1 PixelData
2296: >(FFFE,E000) #0 [] Item
2304: >(FFFE,E000) #70090 [-1\-40\-1\-32\0\16\74\70\73\70\0\1\1\0\0\1\0\1\0\0\..............] Item
72402: (FFFE,E0DD) #0 SequenceDelimitationItem

After converting it with dcm2json tool with the flag "--with-bulkdata"
The result is:

    "7FE00010":{
        "vr":"OB",
        "DataFragment":[
            {
            },
            {
                "InlineBinary":"/9j/4AAQSkZJRgABAQAA..............g//2Q=="
            }
        ]
    }

It cannot be converted back to dcm file, json2dcm fails with the exception:

json2dcm: JsonParser#getString() is valid only KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. But current parser state is START_OBJECT
java.lang.IllegalStateException: JsonParser#getString() is valid only KEY_NAME, VALUE_STRING, VALUE_NUMBER parser states. But current parser state is START_OBJECT
	at org.glassfish.json.JsonParserImpl.getString(JsonParserImpl.java:91)
	at org.dcm4che3.json.JSONReader.getString(JSONReader.java:98)
	at org.dcm4che3.json.JSONReader.readDataFragment(JSONReader.java:346)
	at org.dcm4che3.json.JSONReader.readDataFragments(JSONReader.java:274)
	at org.dcm4che3.json.JSONReader.readAttribute(JSONReader.java:178)
	at org.dcm4che3.json.JSONReader.doReadDataset(JSONReader.java:141)
	at org.dcm4che3.json.JSONReader.readDataset(JSONReader.java:121)
	at org.dcm4che3.tool.json2dcm.Json2Dcm.parseJSON(Json2Dcm.java:377)
	at org.dcm4che3.tool.json2dcm.Json2Dcm.mergeJSON(Json2Dcm.java:358)
	at org.dcm4che3.tool.json2dcm.Json2Dcm.main(Json2Dcm.java:258)

fixing this issue requires patching:

  • JSONWriter.writeValue(Value value, boolean bigEndian)
    to fix direct call
      JSONWriter jsonWriter = new JSONWriter( jsonGen );
      jsonWriter.write(dataset);
  • JSONWriter.readValue(DicomInputStream dis, Fragments frags)
    to fix indirect call
      DicomInputStream dis = new DicomInputStream(new File(fname));
      JSONWriter jsonWriter = new JSONWriter(jsonGen);
      dis.setDicomInputHandler(jsonWriter);
      dis.readDataset(-1, -1);
lexxoff added a commit to lexxoff/dcm4che that referenced this issue Mar 21, 2018
patrick-peer pushed a commit to patrick-peer/dcm4che that referenced this issue Oct 17, 2019
JSONWriter creates invalid json DataFragment element fix dcm4che#254
DicomInputStream: change attributes treated as Bulkdata by default fix dcm4che#388
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant