Closed c1wren closed 3 years ago
To be more explicit, the workaround (or what worked for me) was to point to @seanpianka 's fork, and update my own project to depend on the same Serde versions.
stripe-rust = { git = "https://github.com/seanpianka/stripe-rs.git", branch = "fix-serde" }
serde = "<1.0.118, >=1.0.79"
serde_derive = "<1.0.118, >=1.0.79"
It doesn't look like the maintainers have been active recently with this project, so I'll maintain this fork until this fix is merged to avoid the specific broken version. Once the maintainers merge in this fix, I will delete that fork... but I'll warn here before I do.
It seems like as long as you pin serde to a version before 1.0.119, things work out, ex I have this in my project:
serde = { version = "=1.0.118", features = ["derive"] }
{ version = "=1.0.118", features = ["derive"] }
@marcusbuffett Yep, that works great. Thanks for that!
The fix for this has been merged to master, along with Tokio 1.0 updates:
stripe-rust = { git = "https://https://github.com/wyyerd/stripe-rs.git", branch = "master" }
As far as I can tell, we can avoid using the internal apis altogether (and delete the manual serialize / deserialize code) by using serde untagged
right? If I am understanding right, I'll open a PR
diff --git a/src/resources/payment_source.rs b/src/resources/payment_source.rs
index 6fe9704..cc05822 100644
--- a/src/resources/payment_source.rs
+++ b/src/resources/payment_source.rs
@@ -10,7 +10,8 @@ use serde_derive::{Deserialize, Serialize};
///
/// Not to be confused with `SourceParams` which is used by `Source::create`
/// to create a source that is not necessarily attached to a customer.
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Serialize, Deserialize)]
+#[serde(untagged)]
pub enum PaymentSourceParams {
/// Creates a payment method (e.g. card or bank account) from tokenized data,
/// using a token typically received from Stripe Elements.
@@ -21,48 +22,15 @@ pub enum PaymentSourceParams {
Source(SourceId),
}
-impl<'de> ::serde::Deserialize<'de> for PaymentSourceParams {
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: ::serde::de::Deserializer<'de>,
- {
- use serde::de::{Deserialize, Error};
- use serde::private::de::{Content, ContentRefDeserializer};
- let content = <Content<'_> as Deserialize>::deserialize(deserializer)?;
- let deserializer = ContentRefDeserializer::<D::Error>::new(&content);
- if let Ok(ok) = <SourceId as Deserialize>::deserialize(deserializer) {
- return Ok(PaymentSourceParams::Source(ok));
- }
- let deserializer = ContentRefDeserializer::<D::Error>::new(&content);
- if let Ok(ok) = <TokenId as Deserialize>::deserialize(deserializer) {
- return Ok(PaymentSourceParams::Token(ok));
- }
-
- Err(Error::custom("data did not match any variant of enum PaymentSourceParams"))
- }
-}
-
-impl<'a> ::serde::Serialize for PaymentSourceParams {
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where
- S: ::serde::ser::Serializer,
- {
- match self {
- PaymentSourceParams::Source(id) => id.serialize(serializer),
- PaymentSourceParams::Token(id) => id.serialize(serializer),
- }
- }
-}
-
@wyyerd it may be a good idea to give certain contributors write access to this repo so we can ensure it's maintained promptly.
Perhaps we can open another issue about this? I agree that we need a community member with write access to this repository...
@arlyon Did you open a PR or make these changes in a fork somewhere? I think it would be valuable to support newer versions of Serde.
Edit: Opened #169
In serde v1.0.119, it is no longer possible to compile because
serde::private
is now a private module. The compiler fails atuse serde::private::de::{Content, ContentRefDeserializer};
which is this line: https://github.com/wyyerd/stripe-rs/blob/58c06e798d52bf8a6398b1d556be93e9dce95f7b/src/resources/payment_source.rs#L30