-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: The JSON value could not be converted to System.DateOnly #2920
Comments
Swashbuckle.AspNetCore 6.6 added support for the Could you share an example of what value is trying to be (de)serialized to a |
Unfortunately I don't have a minimal working example right now.
|
I think the missing piece for us what is the string that's trying to be turned into a |
I understand your question but I don't know. I'm not doing any api calls, I'm just trying to load the swagger page where all APIs are listed http://localhost:8080/swagger/ui and the exception pops up. Was working fine with v6.5.0 How can I find the value it's trying to convert to DateOnly? |
I think the only way to get to the bottom of it is to provide a minimal repro project you can share with us that we can then debug. Alternatively, you could clone this repo and reference the project from source rather than NuGet and step through the code to where the exception is coming from. |
After a long debugging, I finally found the problem:
The problem here comes from the [DefaultValue(null)]. Was working fine with v6.5.0, breaks with 6.6.1. Hope it helps. |
For clarity, does it work if you update to 6.6.2, or is it broken with that too? |
No, it doesn't work with this version either. I think we had this attribute so that the default value displayed in Swagger UI would not be filled (otherwise a random string would be displayed). It probably worked because for swagger DateOnly was handled like a "string" (?) |
Removing that attribute fixed the problem, but then you have a default value in Swagger UI, which is probably not the default you want for a nullable value (but that is ok, I guess it always worked like this). But with version 6.5 and earlier you were able to have that behavior by applying the DefaultValue attribute. With 6.6.1 and later an exception is thrown, so a breaking change was introduced here. Any fix soon? |
I haven't had the time to look into it yet. Community contributions to investigate the bug and/or fix are welcome as it would speed things along. |
I am probably going to look at this issue |
Describe the bug
Everything was working fine with v6.5.0. After migrating to v6.6.1 or v6.6.2, I got the following exception
I didn't change any line of code, just migrated the package.
Expected behavior
the json definition should load correctly. Instead, I got an error message.
Actual behavior
This is what I get
Steps to reproduce
No response
Exception(s) (if any)
System.Text.Json.JsonException: The JSON value could not be converted to System.DateOnly.
Swashbuckle.AspNetCore version
6.6.1 and upper
.NET Version
net8.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: