aws_smithy_types::Document already has #[derive(Serialize, Deserialize)] behind a feature flag, but that only lets you serialize the Document itself. it doesn't let you convert an arbitrary struct to a Document directly.
|
#[cfg(any( |
|
all(aws_sdk_unstable, feature = "serde-deserialize"), |
|
all(aws_sdk_unstable, feature = "serde-serialize") |
|
))] |
|
use serde; |
I'd like to be able to do:
let doc = aws_smithy_types::document::to_document(&my_struct)?;
let my_struct: MyStruct = aws_smithy_types::document::from_document(doc)?;
Basically the same thing serde_json does with serde_json::to_value / serde_json::from_value, but targeting Document instead of Value.
This would also allow for interoperability between the type types without client facing code.
Right now the workaround i'm using is to round-trip through serde_json::Value and then manually convert:
let json_value = serde_json::to_value(&my_struct)?;
let doc = json_to_document(json_value); // hand-rolled conversion function
This works but it's clunky and allocates an intermediate representation for no reason.
It would be a significantly more ergonomic client experience to provide a Serializer implementation analogous to serde_json to allow for conversion from arbitrary types directly.
https://github.com/serde-rs/json/blob/master/src/value/ser.rs#L58
aws_smithy_types::Documentalready has#[derive(Serialize, Deserialize)]behind a feature flag, but that only lets you serialize the Document itself. it doesn't let you convert an arbitrary struct to a Document directly.smithy-rs/rust-runtime/aws-smithy-types/src/document.rs
Lines 10 to 14 in a0d46cd
I'd like to be able to do:
Basically the same thing serde_json does with
serde_json::to_value/serde_json::from_value, but targetingDocumentinstead ofValue.This would also allow for interoperability between the type types without client facing code.
Right now the workaround i'm using is to round-trip through
serde_json::Valueand then manually convert:This works but it's clunky and allocates an intermediate representation for no reason.
It would be a significantly more ergonomic client experience to provide a
Serializerimplementation analogous to serde_json to allow for conversion from arbitrary types directly.https://github.com/serde-rs/json/blob/master/src/value/ser.rs#L58