Skip to content

Typeless.Deserialize does not return equivalent dynamic object #224

@sudsy

Description

@sudsy

I came across something a little strange about the way the dynamic objects are structured. The following test fails with the exception Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : 'System.Collections.Generic.Dictionary<object,object>' does not contain a definition for 'Amount':

 [Fact]
        public void testDynamic()
        {
            var v = new { Amount = 108, Message = "Hello" };
            var bin = MessagePackSerializer.Typeless.Serialize(v);
            dynamic newV = MessagePackSerializer.Typeless.Deserialize(bin);
            Assert.Equal(v.Amount, (int)newV.Amount);
            Assert.Equal(v.Message, (string)newV.Message);
        }

While an equivalent test using Newtonsoft passes

 [Fact]
        public void testDynamicJson()
        {
            var v = new { Amount = 108, Message = "Hello" };
            var json = JsonConvert.SerializeObject(v);
            dynamic newV = JsonConvert.DeserializeObject(json);
            Assert.Equal(v.Amount, (int)newV.Amount);
            Assert.Equal(v.Message, (string)newV.Message);
        }

I can see that this would be a breaking change so I didn't even attempt a fix and pull request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions