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

Unexpected brackets in to_value of a newtype struct #77

Closed
dtolnay opened this issue Jun 7, 2016 · 0 comments
Closed

Unexpected brackets in to_value of a newtype struct #77

dtolnay opened this issue Jun 7, 2016 · 0 comments
Assignees
Milestone

Comments

@dtolnay
Copy link
Member

dtolnay commented Jun 7, 2016

#![feature(custom_derive, plugin)]
#![plugin(serde_macros)]

use std::collections::BTreeMap;

extern crate serde_json;

#[derive(Serialize, Deserialize)]
struct Bar(BTreeMap<String, i32>);

fn main() {
    let mut b = Bar(BTreeMap::new());
    b.0.insert(String::from("foo"), 123);

    // prints {"foo":123}
    println!("{}", serde_json::to_string(&b).unwrap());

    let mut outer = BTreeMap::new();
    outer.insert(String::from("outer"), serde_json::to_value(&b));

    // prints {"outer":[{"foo":123}]}
    println!("{}", serde_json::to_string(&outer).unwrap());
}

I would expect the second print to be {"outer":{"foo":123}}.

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

No branches or pull requests

1 participant