msgpack-cli icon indicating copy to clipboard operation
msgpack-cli copied to clipboard

Problem with packing and unpacking a dictionary inside another dictionary

Open aidin36 opened this issue 10 years ago • 0 comments

I packed a dictionary, which contains another dictionary inside of it. When I unpacked that again, instead of the inner dictionary, I found an integer. (count of the keys of the inner dictionary).

Following code will produce the problem.

I used the latest code of master. With VS 2010, and .Net Framework 3.5.

Dictionary<string, object> data = new Dictionary<string,object>();

data["name"] = "test";
data["age"] = 20;

Dictionary<string, object> innerDict = new Dictionary<string, object>();
innerDict["x"] = 13.5;

data["inner-dict"] = innerDict;

SerializationContext context = new SerializationContext();
context.CompatibilityOptions.PackerCompatibilityOptions = MsgPack.PackerCompatibilityOptions.None;
MessagePackSerializer<object> serializer = MessagePackSerializer.Get<object>(context);

Stream packed = new MemoryStream();
serializer.Pack(packed, data);

packed.Seek(0, SeekOrigin.Begin);

object unpacked = serializer.Unpack(packed);
// unpacked: { "name" : "test", "age" : 20, "inner-dict" : 1 }

aidin36 avatar Dec 24 '14 13:12 aidin36