20 lines
623 B
C#
20 lines
623 B
C#
using System.Text.Json;
|
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
|
|
namespace ConsoleApp.Data;
|
|
|
|
internal static class BarcodesJsonConverter
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new();
|
|
|
|
public static ValueConverter<List<string>, string> Instance { get; } = new(
|
|
v => Serialize(v),
|
|
v => Deserialize(v));
|
|
|
|
private static string Serialize(List<string> value) =>
|
|
JsonSerializer.Serialize(value, JsonOptions);
|
|
|
|
private static List<string> Deserialize(string value) =>
|
|
JsonSerializer.Deserialize<List<string>>(value, JsonOptions) ?? [];
|
|
}
|