Enums break ReadAsync()

ReadAsync<ODataServiceResult>() does not work when there are enums in the entity. You get an exception as follows:

The JSON value could not be converted to <Your Enum Type>...

Because OData Web API returns enum values as their string representations instead of numeric values.

You need to update your code to use a JsonStringEnumConverter as follows:

var options = new JsonSerializerOptions
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    PropertyNameCaseInsensitive = true,
options.Converters.Add(new JsonStringEnumConverter());
return stream.Length > 0 ? await JsonSerializer.DeserializeAsync<T>(stream, options) : default(T);

Or if there's a reason not to do so, then you should add a parameter to ReadAsync() of type JsonSerializerOptions, so we can control that ourselves.

Hi @vnmatt,

Check this thread for more info: