Enum type no longer working in .Net core 3.0 FromBody request object

前端 未结 3 1397
暗喜
暗喜 2021-01-03 21:37

I have recently upgraded my web api from .Net core 2.2 to .Net core 3.0 and noticed that my requests are getting an error now when I pass an enum in a post to my endpoint.

3条回答
  •  萌比男神i
    2021-01-03 22:07

    Support for serializing enums as strings already exist if you use the built-in JsonStringEnumConverter and pass that into the JsonSerializerOptions: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonstringenumconverter?view=netcore-3.0

    Here's a sample test that uses it: https://github.com/dotnet/corefx/blob/master/src/System.Text.Json/tests/Serialization/ReadScenarioTests.cs#L17

提交回复
热议问题