Skip to content

not working deserialazer in controller  #33

@Jump33

Description

@Jump33

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."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions