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

Unit structs encode differently between sval_json and serde_json #189

Open
KodrAus opened this issue Jan 31, 2024 · 0 comments
Open

Unit structs encode differently between sval_json and serde_json #189

KodrAus opened this issue Jan 31, 2024 · 0 comments

Comments

@KodrAus
Copy link
Collaborator

KodrAus commented Jan 31, 2024

#[derive(sval::Value, serde::Serialize)]
pub struct MyStruct;

fn main() {
    println!("{}", sval_json::stream_to_string(Some(MyStruct)).unwrap());
    println!("{}", serde_json::to_string(&Some(MyStruct)).unwrap());
}

prints:

"MyStruct"
null

In sval_json, we print the name of the unit struct because we treat them the same as unit variants. In serde_json, unit structs are encoded as null.

sval_json attempts to be serde_json compatible in encoding, so this is worth calling out, but can't be changed at this point.

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

No branches or pull requests

1 participant