-
Notifications
You must be signed in to change notification settings - Fork 10k
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
ProblemDetails serialization to Xml uses incorrect casing #7715
Comments
Is your |
@pranavkm Yes, it is already set to 2.2.
|
You have to DI in the formatters rather than add the formatters manually for it to be configured correctly. Something along the lines of services
.AddMvc(config => { ...})
.AddXmlSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.Configure<MvcOptions>(options =>
{
var outputFormatter = options.OutputFormatters.OfType<XmlSerializerOutputFormatter>().First();
outputFormatter.WriterSettings.Indent = true;
outputFormatter.WriterSettings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
}); |
Ouch. OK, that does look better. Now I get responses like this for xml:
and this for json:
Now I just have to get swagger to agree that is what it is going to send back.
and I put
|
It does seem odd that in XML, the messages are joined together by a space so that it returns a single string like this Makes creating a unified model rather difficult. Pick one and stick with it for both formats. Either return a string with all the messages combined, or return an array of strings, but don't change it based on the serializer. |
The RFC has a very specific format for representing arrays in XML - https://tools.ietf.org/html/rfc7807#appendix-A - something that skipped due to time constraints when initially implementing this feature. Error values would need to be represented using this format since it's an array of strings: <MVC-Errors>
<Recipient.Zip>
<i>Zip '6009' is not valid for country 'UNITED STATES'.</i>
</Recipient.Zip>
<Recipient.LastName>
<i>The fields FirstName and LastName must be strings with a combined maximum length of '39'.</i>
</Recipient.LastName>
<Recipient.FirstName>
<i>The fields FirstName and LastName must be strings with a combined maximum length of '39'.</i>
<i>This is the second error message for FirstName</i>
</Recipient.FirstName>
</MVC-Errors> We'd be happy to accept a PR if this is something you would be interested in improving. Here are the relevant types:
I'm closing this issue since the initial question was resolved. |
Describe the bug
ValidationProblemDetails/ProblemDetails serialization to Xml uses incorrect casing
To Reproduce
Steps to reproduce the behavior:
using ASP.NET Core 2.2
return a ValidationProblemDetails and you get something similar to the following:
Expected behavior
Conform to the example https://tools.ietf.org/html/rfc7807#page-15
Additional context
Xml is a case-sensitive format, so casing here is important. Additionally, the errors node is not serialized by default which leaves a poor user experience for anyone expecting Web API to work for both JSON and XML formats.
The text was updated successfully, but these errors were encountered: