Skip to content

Serialize with nested class #236

@NextSim

Description

@NextSim

I have class definitions that include a nested class

    [MessagePackObject]
    public class enableApiShell
    {
        [Key(0)]
        public int type { get; set; }
        [Key(1)]
        public UInt32 msgid { get; set; }
        [Key(2)]
        public string command { get; set; }
        [Key(3)]
        public enableApiHelper val { get; set; }
    }

    [MessagePackObject]
    public class enableApiHelper
    {
        [Key(0)]
        public bool val { get; set; }
    }

but this won't serialize, it gets an exception

System.InvalidOperationException: code is invalid.
   at MessagePack.Decoders.InvalidBoolean.Read()
   at MessagePack.Formatters.Simulator_enableApiHelperFormatter2.Deserialize(Byte[] , Int32 , IFormatterResolver , Int32& )
   at MessagePack.MessagePackSerializer.Deserialize[T](Byte[] bytes, IFormatterResolver resolver)
   at Simulator.tcpClientBase.ConnectCallback(IAsyncResult ar) 

However, if I change the key for the enableApiHelper to 4 it doesn't generate the exception, but it adds four 'null' values

[
  0,
  1,
  "enableApiControl",
  [
    null,
    null,
    null,
    null,
    true
  ]
]

I need it to be

[
  0,
  1,
  "enableApiControl",
  [
    true
  ]
]

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