Replies: 1 comment
-
The feature is implemented as the |
Beta Was this translation helpful? Give feedback.
0 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.
-
From time to time the question comes up how to serialize a string or a list of string. Something like
This can be solved with an untagged enum:
This works but has the "downside" that it remembers if the input was a single value or a list. This distinction is not always necessary. It also hard codes the choice of sequence to a
Vec
. For this crate the downside is also that theserde_as
system doesn't work in such a setup.The first two can be fixed by writing custom deserialization code which converts both variants into the same collection type.
The idea is to provide a new adapter type which works like this:
The
OneOrMany
will always return a collection type during deserialization and apply theserde_as
conversions. For serialization two options are possible: prefer single, or prefer list. In the prefer single case, if the collection has length 1 it serializes asT
. In the prefer list case it always chooses to serialize a sequence.Beta Was this translation helpful? Give feedback.
All reactions