Moving common code to shared lib
This commit is contained in:
22
shared/Serializer/JsonSerializer.cs
Normal file
22
shared/Serializer/JsonSerializer.cs
Normal file
@ -0,0 +1,22 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user