doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
715 stars 124 forks source link

MessagePack deserialization ignores key attributes #341

Closed derevnjuk closed 8 months ago

derevnjuk commented 9 months ago

The current implementation of the SocketIOMessagePackSerializer does not correctly deserialize message data. Specifically, it fails to recognize and map the data to the corresponding fields, even when key attributes are utilized.

Steps to Reproduce:

  1. Define a MessagePack object, like the MessagePackUserDto class shown below:

    [MessagePackObject]
    public class MessagePackUserDto
    {
    [Key("username")]
    public string Username { get; set; } = null!;
    
    [Key("email")]
    public string Email { get; set; } = null!;
    }
  2. Receive a message from the server with data like this:
    {"username": "admin", "email": "test@example.com"}
  3. Attempt to deserialize the received data using the GetValue<MessagePackUserDto>() method.

Actual Behavior:

Currently, the GetValue<T>() method does not properly map the received data to the class. Instead, it results in an instance of class with fields initialized to null, even when the key attributes are used.

derevnjuk commented 8 months ago

@doghappy could you release these changes to NuGet?

doghappy commented 8 months ago

released, thank for the PR