-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Inconsistency between serialize and deserialize in Serde #138
Comments
Sorry, I'm not understanding the problem. Does this lead to an actual issue in your code? Like it makes sense that these would be different at a conceptual level. Serialization is guaranteed to produce valid UTF-8, so it serializes a string. But deserialization can be done on a |
Not really an issue: I simply need to add I was merely surprised: so far I only encountered types that use |
Do you agree that it makes sense given that parsing works on Now if you're layering stuff on top of this where only strings make sense, then it should be fine if you just use (It's possible I have a misunderstanding here.) |
Oh sorry. I think I did not explain myself clearly. I completely agree that accepting both The only thing that would change would be: impl<'de> serde::Deserialize<'de> for Zoned {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Zoned, D::Error> {
use serde::de;
struct ZonedVisitor;
// ...
- deserializer.deserialize_bytes(ZonedVisitor)
+ deserializer.deserialize_str(ZonedVisitor)
}
} E.g., in As I said most types I encountered were symmetric in the Serde type they serialized to and the type they requested from the deserializer. Not sure whether this is a general good practice in the implementation of the Serde traits. Hence, I wanted to give you a quick heads up. |
You're saying that if I used |
Puh. I have to admit the Serde API with its asymmetry between Serialize and Deserialize is still somewhat confusing. Re. this issue:
So in this case, the fact that you are calling I always interpreted the call to |
Interesting. I'll leave this open for now since it seems deserving of a deeper dive on my part. The visitors in this crate do also accept both strings and bytes. I agree that a string is, I guess, the "preferred" type in this context. |
I guess, this change would also be a visible, hence breaking, one. So not sure it's worth the effort. |
Well I guess that gets to my question: what is the actual behavior difference? In either case, my plan with Jiff is to do 1-2 breaking changes leading up to Summer 2025, and then publish Jiff 1.0. So if it's really a breaking change, that's fine, it can be included in |
Deserializing `jiff` types from YAML is not currently possible. Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. These tests serve in both - proving the current incompatibility - verifying the fix in the following commit, which migrates `Deserialize` implementations to `deserializer.deserialize_str`. Related to BurntSushi#148, BurntSushi#138
Deserializing `jiff` types from YAML was previously not possible: Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. This changset migrates `Deserialize` implementations to `deserializer.deserialize_str`, thus providing serde YAML compatibility. Fixes BurntSushi#148, BurntSushi#138
Deserializing `jiff` types from YAML is not currently possible. Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. These tests serve in both - proving the current incompatibility - verifying the fix in the following commit, which migrates `Deserialize` implementations to `deserializer.deserialize_str`. Related to BurntSushi#148, BurntSushi#138
Deserializing `jiff` types from YAML was previously not possible: Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. This changset migrates `Deserialize` implementations to `deserializer.deserialize_str`, thus providing serde YAML compatibility. Fixes BurntSushi#148, BurntSushi#138
Deserializing `jiff` types from YAML is not currently possible. Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. These tests serve in both - proving the current incompatibility - verifying the fix in the following commit, which migrates `Deserialize` implementations to `deserializer.deserialize_str`. Related to BurntSushi#148, BurntSushi#138
Deserializing `jiff` types from YAML was previously not possible: Neither `serde_yaml` nor its maintained fork `serde_yml` support deserializing from bytes. This changset migrates `Deserialize` implementations to `deserializer.deserialize_str`, thus providing serde YAML compatibility. Fixes BurntSushi#148, BurntSushi#138
jiff
uses inconsistent Serde types in serialization / deserialization.jiff
typesserializer.collect_str()
) (example)deserializer.deserialize_bytes(visitor)
) (example)It's not a huge issue, but I wanted to give a heads up: this inconsistency tripped me up in a couple of places, while adding support for
jiff
to my crate. I am now making my own impl more robust, by adding adeserialize_bytes
impl to everydeserialize_str
impl :)The text was updated successfully, but these errors were encountered: