Skip to content

Please provide a method to force order when using keyAsPropertyName #191

@MaySamuel

Description

@MaySamuel

With keyAsPropertyName: true it's not possible to force key order.

The problem is that class inheritance leads to an (for me) unexpected order and there is no builtin method to influence the messagepack generator in a appriorate way.

    [MessagePack.MessagePackObject(keyAsPropertyName: true)]
    public abstract class AbstractBase
    {
        public UInt32 Id = 0xaa00aa00;
    }

    public sealed class RealClass : AbstractBase
    {
        public String Str;
    }

    static async Task Main(string[] args)
    {
        RealClass realClass = new RealClass { Str = "X" };
        var msgRawData = MessagePack.MessagePackSerializer.Serialize(realClass);

        // msgRawData result: 82A3537472A158A24964CEAA00AA00
        //                                        ^^^^^^^^^^
        //                                        Id from abstract base class can be found at the end.
    }

So I cannot easily "sniff" the abstract property UInt32 Id from the raw byte array because it's not at the beginning.

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