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
-
I have input to deserialize into a model that may or may have been combined. For instance, the input may be in two payloads
and
And these are trivially deserializable:
The problem is that the input may be combined
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
Model
fromA
andB
instances 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 ofA
andB
fields:The manually flattened deserialization is a not ideal from a maintenance perspective (imagine if
A
andB
had 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 withflatten
Beta Was this translation helpful? Give feedback.
All reactions