22 lines
595 B
C#
22 lines
595 B
C#
|
using Confluent.Kafka;
|
||
|
using System.Text.Json;
|
||
|
|
||
|
namespace Serializers
|
||
|
{
|
||
|
public class JsonSerializer<T> : ISerializer<T>, IDeserializer<T>
|
||
|
{
|
||
|
public byte[] Serialize(T data, SerializationContext context)
|
||
|
{
|
||
|
return JsonSerializer.SerializeToUtf8Bytes(data);
|
||
|
}
|
||
|
|
||
|
public T Deserialize(ReadOnlySpan<byte> data, bool isNull, SerializationContext context)
|
||
|
{
|
||
|
if (!isNull)
|
||
|
{
|
||
|
return JsonSerializer.Deserialize<T>(data);
|
||
|
}
|
||
|
throw new Exception ("Data cannot be null");
|
||
|
}
|
||
|
}
|
||
|
}
|