Swagger ui's example value/scheme doesn't respect JsonConverters #48792
-
Let's suppose I have the following classes: public class Student
{
public string Name { get; set; }
[JsonConverter(typeof(CultureInfoJsonConverter))]
public CultureInfo Culture { get; set; }
public Student() { }
public Student(string name, string culture) => (Name, Culture) = (name, new CultureInfo(culture));
} A converter for public class CultureInfoJsonConverter : JsonConverter<CultureInfo>
{
public override CultureInfo? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var languageCode = reader.GetString();
return string.IsNullOrWhiteSpace(languageCode) ? null : new CultureInfo(languageCode);
}
public override void Write(Utf8JsonWriter writer, CultureInfo value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString());
}
} And the following [HttpGet("student")]
[Produces(MediaTypeNames.Application.Json)]
public ActionResult<Student> GetStudent() => Ok(new Student("Bob", "en-US")); When viewing the swagger/redoc pages, it shows |
Beta Was this translation helpful? Give feedback.
Answered by
gfoidl
Jun 14, 2023
Replies: 1 comment
-
I created an issue out of this -- let's discuss that over there. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
senketsu03
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created an issue out of this -- let's discuss that over there.