Hi Radzen
I have an entity with an enum
property. When posting the entity to the server, I have an invalid ModelState, with the following error message:
Exception = "Cannot read the value '0' as a quoted JSON string value."
Inspecting the request body I see the property gets serialized to an int
, and from looking around it seems OData expects an enum
to be serialized to a string
.
Passing in the following options to ODataJsonSerializer.Serialize
in my AppDbService.cs
didn't have any effect.
JsonSerializerOptions options = new JsonSerializerOptions
{
Converters = { new JsonStringEnumConverter() }
};
When adding the following attribute to the property, I was able to get the serializer to convert it to its string representation.
[JsonConverter(typeof(JsonStringEnumConverter))]
Not sure if this behaviour is expected, or whether this might just assist someone in the future.