Skip to content

Unable to serialise class with non-settable collection #62

@nzbart

Description

@nzbart

Microsoft mandates that classes must not expose settable collection properties. I'm not aware of any classes in the BCL that violate this rule.

Unfortunately, msgpack doesn't serialise instances that comply with this rule. JSON.NET and System.Xml.Serialization.XmlSerializer both use the Add method on the collection to support non-settable collections.

Below is a test that fails that I think should pass:

    class CompliantClass
    {
        //compliant with Microsoft guidelines at https://msdn.microsoft.com/en-us/library/dn169389%28v=vs.110%29.aspx:
        // "X DO NOT provide settable collection properties."
        public List<int> Integers { get; private set; }

        public CompliantClass()
        {
            Integers = new List<int>();
        }
    }

    //This test currently fails, but I would like it to pass
    [Test]
    public void Given_a_class_with_non_settable_list_property_When_serialised_with_msgpack_Then_no_exception_should_be_thrown()
    {
        SerializationContext.Default.GetSerializer<CompliantClass>();
    }

Is there a way to get msgpack to support this style of class?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugDetected as bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions