New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
serde_as
does not process enum variant attributes
#499
Comments
I think I identified the issue. The problem is that the #[serde_with::serde_as]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "messageType", content = "content")]
/// The contents of a message combined with the `MessageType`
pub enum MessageContentJsonStringEnum {
/// A normal message
Text(String),
/// Fancy object message
#[serde_as(as = "serde_with::json::JsonString")]
Object(crate::MessagePayload),
} Instead, you can write this. /// Fancy object message
Object(
#[serde_as(as = "serde_with::json::JsonString")]
crate::MessagePayload
), It might be worthwhile to extend the macro to support variant attributes too. |
serde_as
does not process enum variant attributes
Ah that makes sense, than you, that solves the main issue I had 👍
If that basically achieves the same result, a simpler alternative might just be to add an example of the attribute being used "within" the enum definitions to the docs? :) |
Change the serde_as macro to warn on serde_as attributes on enum variant fields. They are unsupported (in contrast to serde_derive), so showing an error is better and avoids confusion when migrating. Also update the main examples to include an enum.
Change the serde_as macro to warn on serde_as attributes on enum variant fields. They are unsupported (in contrast to serde_derive), so showing an error is better and avoids confusion when migrating. Also update the main examples to include an enum.
I decided not to support |
502: Better handle serde_as on enum variants #499 r=jonasbb a=jonasbb Change the serde_as macro to warn on serde_as attributes on enum variant fields. They are unsupported (in contrast to serde_derive), so showing an error is better and avoids confusion when migrating. Also update the main examples to include an enum. Closes #499 Co-authored-by: Jonas Bushart <jonas@bushart.org>
In my attempt to update to
serde_with@2.0.0
I noticed that nested JSON support is gone, with a changelog stating that:It doesn't seem quite as simple as that though, as I can't figure out a way to achieve what worked with
json::nested
usingJsonString
.Minimal example which contains example JSON files and tests: https://github.com/ljoonal/serde_with_nested_json
My expectation is that
JsonString
should work just likejson:nested
did, but instead it fails for a reason that is beyond my debugging skills. But I've at least narrowed it down to working with the structs but breaking with the enums in the linked example repo.As to why support for this would be nice, a real world usecase is de-serializing an external JSON API's responses that contain nested json of different types, but also sometimes just plain strings.
The text was updated successfully, but these errors were encountered: