Closed steven-joruk closed 4 years ago
I'm not sure there's a built-in way to do this at present.
The simplest way, assuming you just have one or two enums like this, would be to impl TryFrom<String>
and Into<&'static str>
for each enum, and then put #[serde(try_from = "String")]
and #[serde(into = "&'static str")]
attributes on the enum (you might be able to use &str
instead of String
).
This certainly is a feature that could directly be supported by this library, or ideally by serde itself.
That solution is good for me, thanks. I've used the method in the original post when using serde_json, but I haven't looked at how it's implemented.
FYI this seems to be the change that enables this behavior in serde_json: https://github.com/serde-rs/json/pull/76.
Hello, I'm not sure if this requires a feature request, or of I'm just misusing the library. How would you achieve this serialization?
Expected XML format:
Actual:
Thanks