Skip to content

Serialization

When using the System.Text.Json serializer, the default converter behaviour is to treat IByteBuffer instances as a byte[] and serialize it as such, which results in a base64 encoded string.

However, it is possible to change this behaviour and serialize the buffer as a hex string instead. This can be useful for consumers that expect such format, or for debugging purposes, since it's a format that might be more readable to protocol developers.

To do this, simply annotate the property with the ByteBufferJsonConverter attribute and set the HexString format.

public class MyObject
{
    public string? Id { get; set; }

    [ByteBufferJsonConverter( Format = ByteBufferSerializerFormat.HexString )]
    public IByteBuffer? Buffer { get; set; }
}

Note

This attribute is only available when using System.Text.Json serializer. If you are using Newtonsoft.Json, you will need to implement a custom converter to achieve the same result.