An improved flatten attribute #668
Unanswered
nickbabcock
asked this question in
Q&A
Replies: 1 comment 5 replies
-
|
There is nothing for this purpose in Such a macro could be a suitable addition for |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have input to deserialize into a model that may or may have been combined. For instance, the input may be in two payloads
{ "foo": "hello" }and
{ "bar": "world" }And these are trivially deserializable:
The problem is that the input may be combined
{ "foo": "hello", "bar": "world" }And the same model should be constructed in both situations whether the input is combined or not:
I know before deserialization if the input is combined or split, so creating
ModelfromAandBinstances are easy.The problem is with the combined format is
#[serde(flatten)]has many issues (here is one of them), so I need to manually create a flattened struct that is a copy and paste ofAandBfields:The manually flattened deserialization is a not ideal from a maintenance perspective (imagine if
AandBhad 50 fields each), and may be error prone.My question is, is this possible with
serde_with, or something that would be possible and within scope? Not sure how much leeway there already is withflattenBeta Was this translation helpful? Give feedback.
All reactions