Skip to content
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

fix: Fixed untagged enum deserialization issues #194

Closed
wants to merge 1 commit into from

Conversation

Wicpar
Copy link

@Wicpar Wicpar commented Dec 14, 2023

Fixes #167

There is maybe a better way to deserialize, but would not be as simple.

Comment on lines +214 to +219
let value = Value::deserialize(deserializer)?;
if let Ok(response) = serde_json::from_value(value.clone()) {
return Ok(Self::Response(response))
}
use serde::de::{Error};
Ok(Self::Event(serde_json::from_value(value.clone()).map_err(|err|Error::custom(format!("{:?}", err)))?))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, how is this different from untagged deserialization?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CdpEventMessage deserialization doesn't play nice with untagged enums, i don't remember exactly why, but this adds the necessary coersion for it to work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it was fixed in the meantime somehow, let me try on master for a bit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't seem to be happening anymore, but longer tests are necessary

@MOZGIII
Copy link
Contributor

MOZGIII commented Dec 17, 2023

This looks a bit off, let me take a stab at this

@MOZGIII
Copy link
Contributor

MOZGIII commented Dec 17, 2023

Let's add the #[serde(untagged)] variant to the messages enum instead?
https://serde.rs/variant-attrs.html#untagged

This should work for a generic "fallback" type.

@Wicpar
Copy link
Author

Wicpar commented Jan 8, 2024

I'm closing this as i no longer encounter the issues in the most recent version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Critical Deserialization issue
3 participants