Repository navigation
Is there a way to deserialize an empty list as None?
#970
|
Basically, if I have struct Thing {
list: Option<Vec<u32>>,
other: u32,
}and the JSON {
"list": [],
"other": 0
}I want it to deserialize it into Thing {
list: None,
other: 0,
}so empty lists are mapped to Obviously I can just write a helper function for this and use If this does not exist but you'd be interested in something like it (maybe Thank you! |
Replies: 1 comment 1 reply
|
Hi, no that is not currently implemented. It's implementation probably has to differ a bit from |
Hi, no that is not currently implemented. It's implementation probably has to differ a bit from
NoneAsEmptyString. For one I am not sure if a simple visitor like that is possible or if deserialization just always has to create theVec. At least for submission to this crate it should be possible to customize the inner type of theVec.I am open to adding this to the crate. While I'm not sure how frequently used this pattern is, the implementation is likely just a couple of lines plus docs and tests.