Skip to content

JSON serialization of HashMaps with Enum keys is broken #21470

Closed
rust-lang-deprecated/rustc-serialize
#32
@japaric

Description

@japaric

STR

extern crate serialize;

use serialize::json;
use std::collections::HashMap;

#[derive(Encodable, Eq, Hash, PartialEq)]
enum Enum {
    Foo,
    Bar,
}

fn main() {
    let mut map = HashMap::new();
    map.insert(0, 0);
    println!("{}", json::encode(&map));

    let mut map = HashMap::new();
    map.insert(Enum::Foo, 0);
    println!("{}", json::encode(&map));
    println!("^ what?!");
}

Output

{"0":0}
{
^ what?!

Version

rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)

The second hashmap was properly being serialized as {"Foo":0} with a two days old nightly (rustc 1.0.0-nightly (dcaeb6aa2 2015-01-18 11:28:53 +0000)).

cc @aturon @alexcrichton @gankro

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions