Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[json] Allow null for string values
Browse files Browse the repository at this point in the history
feliwir committed Mar 7, 2024
1 parent d9b94c6 commit e941328
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions json/src/de/mod.rs
Original file line number Diff line number Diff line change
@@ -194,8 +194,10 @@ where
| VR::TM
| VR::UC
| VR::UI => {
let items: Vec<String> =
let items: Vec<Option<String>> =
serde_json::from_value(value).map_err(A::Error::custom)?;
let items: Vec<String> =
items.into_iter().map(|v| v.unwrap_or_default()).collect();
values = Some(PrimitiveValue::Strs(items.into()).into());
}

@@ -370,7 +372,7 @@ impl<'de> Deserialize<'de> for DicomJson<Tag> {
#[cfg(test)]
mod tests {
use super::from_str;
use dicom_core::{DataElement, Tag, VR};
use dicom_core::{dicom_value, smallvec::smallvec, DataElement, PrimitiveValue, Tag, VR};
use dicom_object::InMemDicomObject;

#[test]
@@ -428,4 +430,49 @@ mod tests {
Some(&DataElement::new(tag, VR::CS, "ISO_IR 192")),
)
}

#[test]
fn can_parse_null_values() {
let serialized = serde_json::json!({
"00080008": {
"Value": [
"DERIVED",
"PRIMARY",
"POST_PROCESSED",
"RT",
null,
null,
null,
null,
"100000"
],
"vr": "CS"
}
});

let obj: InMemDicomObject = super::from_value(serialized).unwrap();

let tag = Tag(0x0008, 0x0008);
assert_eq!(
obj.get(tag),
Some(&DataElement::new(
tag,
VR::CS,
dicom_value!(
Strs,
[
"DERIVED",
"PRIMARY",
"POST_PROCESSED",
"RT",
"",
"",
"",
"",
"100000",
]
)
)),
)
}
}

0 comments on commit e941328

Please sign in to comment.