Код: Выделить всё
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var json = @"{
""enum-one"": 1.1
}";
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = {
new JsonStringEnumConverter(JsonNamingPolicy.KebabCaseLower)
}
};
var enumOne = JsonSerializer.Deserialize(@"""enum-one""", options); // This works
var enumDictionary = JsonSerializer.Deserialize(json, options); // This will throw error
}
}
public enum TestEnum
{
EnumOne = 1,
EnumTwo = 2,
EnumThree = 3
}
Демонстрация кода: https://dotnetfiddle.net/XA0uPX
Я что-нибудь делал ошибаюсь или чего-то не хватает?
Подробнее здесь: https://stackoverflow.com/questions/791 ... tion-error
Мобильная версия