Skip to content
Better HN
Top
Best
Ask
Show
New
Jobs
Search
⌘K
0 points
q3k
5y ago
0 comments
Save
Share
How would you express deserializing these 'polymorphic JSON' objects using serde/Rust?
0 comments
3 comments · 1 top-level
top
newest
oldest
speedgoose
5y ago
· 2 in thread
Using a rust enum I guess.
q3k
OP
5y ago
You're right, this does seem to work [1]. I wasn't aware that serde would attempt to deserialize multiple enum variants until something matches.
[1] -
https://serde.rs/enum-representations.html#untagged
masklinn
5y ago
Yeah that's a rather common scheme out there so Serde does provide built-in support for this deserialisation. Probably better for deserialisation performances to use properly tagged enums, but if you don't have a choice Serde's got your back.
j
/
k
navigate · click thread line to collapse