-
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
JSONProperty not working correctly in immutable models #2057
Comments
Have you configured Swashbuckle to honor Newtonsoft behavior instead of STJ (the default) as described in the readme? Also, your example link is broken |
Yes, Swashbuckle is configured correctly - you can see that The problem is that the Swashbuckle anlayzer for NewtonSoft doesn't allow for using I'll try attaching the project again here: |
OK dicovered the issue and fixed with a6eda1a. Should now be available as of |
This has resolved the issue - thanks for the prompt update. |
When using NewtonsSoft serialization, ASP.Net Core supports model binding using immutable models in controller methods. To work, this requires that the model has a constructor which has an argument for each JSON property with the same name as the property name (allowing a camel case vs. title case difference). This is also compatible with using
[JsonProperty]
to rename a property - the constructor has an argument with the real property name but it binds to the name specified in the[JsonProperty]
.In the following controller, the two methods
Mutable
andImmutable
both have the same JSON signature:With NewtsonSoft serialization, both of these methods will accept the JSON POST body of:
However, the swagger.json generated is:
Swashbuckle isn't allowing for the
[JsonProperty]
binding logic and is incorrectly markingprop2
as read-only.Example project: SwashTest.zip
The text was updated successfully, but these errors were encountered: