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

to_string(from_str::<Value>("ron")) should be lossless #189

Open
Tracked by #397
CAD97 opened this issue Oct 7, 2019 · 1 comment · May be fixed by #328
Open
Tracked by #397

to_string(from_str::<Value>("ron")) should be lossless #189

CAD97 opened this issue Oct 7, 2019 · 1 comment · May be fixed by #328
Labels

Comments

@CAD97
Copy link
Contributor

CAD97 commented Oct 7, 2019

The specific case I'm running into that fails to round trip is serializes via Serializer::serialize_newtype_variant. I believe that this is because Value doesn't store the name of the struct stored, so deserialized named things become unnamed sequences.

cc #122

@kvark kvark added the bug label Oct 7, 2019
@pheki
Copy link
Contributor

pheki commented Jan 29, 2021

I'm not sure this is possible with the current serde::Serializer trait, as serialize_newtype_variant takes a &'static str as name, which we can't get when deserializing (unless we leak a String).

I also made a simple test for the same problem but with Struct instead:

use ron::Value;

#[test]
fn struct_round_trip() {
    let ron_str = "GameConfig(field: 2)";
    let value: Value = ron::from_str(ron_str).unwrap();
    let reserialized = ron::to_string(&value).unwrap();
    assert_eq!(ron_str, reserialized);
}

It fails with "GameConfig(field: 2)" != "({\"field\":2})"

It also seems to me that the deserialization step would be impossible to implement following the abstraction proposed by serde in which Value would be independent of the serializer as Visitor does not have a visit_struct method, so there's no way to communicate to the visitor that its visiting a struct, only a map (see how deserialize_struct calls visit_map here).

Maybe there could be a hack by coupling ron::Value to ron::Deserializer and ron::Serializer.

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

Successfully merging a pull request may close this issue.

3 participants