RabbitExpress

An easy to use RabbitMQ Client for .Net.

View on GitHub

JSON Serializer

This library provides an implementation of a very simple serializer.

Add the reference

In your csproj add a PackageReference to this package.

<ItemGroup>
    <PackageReference Include="RabbitExpress.Serializers.JsonSerializer" Version="1.*" />
</ItemGroup>

The serializer

This is a very simple serializer to be used in the RabbitExpress.QueueClient. The implementation uses Newtonsoft.Json to serialize and deserialize the transfered messages.

public class JsonSerializer : IExpressSerializer
{
    public TObject Deserialize<TObject>(byte[] data)
    {
        var raw = Encoding.UTF8.GetString(data);
        return JsonConvert.DeserializeObject<TObject>(raw,
            new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto });
    }

    public byte[] Serialize<TObject>(TObject value)
    {
        var ser = JsonConvert.SerializeObject(value, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });
        return Encoding.UTF8.GetBytes(ser);
    }
}