News for hackers. Stuff that matters.
Re:OAuth 3 by q3k on Thursday October 22, 2020 @11:40AM (#24859196)
How would you express deserializing these 'polymorphic JSON' objects using serde/Rust?
Re:OAuth 3 by speedgoose on Thursday October 22, 2020 @11:44AM (#24859255)
Using a rust enum I guess.
Re:OAuth 3 by q3k on Thursday October 22, 2020 @11:54AM (#24859359)
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

Re:OAuth 3 by masklinn on Thursday October 22, 2020 @12:05PM (#24859509)
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.