-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Settings for controller:
builder.Services.AddControllers().AddJsonOptions(options =>
{ options.JsonSerializerOptions.Converters
.Add(new JsonStringEnumMemberConverter());
});
Enums:
using System;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace OCPIServer.Application.Ocpi.Contracts.Enums.Versioning;
//I tried with and without attributes
//[JsonStringEnumMemberConverterOptions(deserializationFailureFallbackValue: OcpiVersion.Unknown)]
//[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum OcpiVersion
{
[EnumMember(Value = "unknown")]
Unknown = 0,
[EnumMember(Value = "2.0")]
v2_0 = 200,
[EnumMember(Value = "2.1")]
v2_1 = 210
}
Controller(endpoint):
[HttpGet("versions/{version}")]
public GetVersionModel GetVersions(OcpiVersion version)
{
return _ocpiVersionsService.GetVersion(version);
}
Everything works if you set 210 or v2_1_0 in the request. But I need the value (2.1.0) to be specified in the request. Like this
https://localhost:7059/.../versions/2.1.0.
But that doesn't work. Deserialization does not occur. I get error 400 "The value '2.1.0' is not valid."