Description
This issue has been moved from a ticket on Developer Community.
I'm using swagger/index page for testing my API. I need both JSON and XML serialization. Json is working fine but the xml serialization generated by swagger contains non-capital letters of node names for capital letter started properties of my [DataContract].
Steps:
1) Add XML serialization formatters:
builder. Services.AddControllers(). AddXmlSerializerFormatters();
2) Data contract class:
[DataContract]
public class DataRequest
{
[DataMember]
public DateTime FromDate { get; set; }
[DataMember]
public DateTime ToDate { get; set; }
}
3) Add EF controller with only one Post method:
[HttpPost]
public async Task<ActionResult<IEnumerable<DataReply>>> Request(DataRequest dataReply)
{
return await _context. DataReply.ToListAsync();
}
Set break-point on return await at post-method.
4) Run (F5) and Try it out:
Json request (application/json):
{
"fromDate": "2021-11-13T00:12:13.725Z",
"toDate": "2021-11-13T00:12:13.725Z"
}
As result, request instance is correct (see attached picture "json serialization in swagger.png")
Xml request (application/xml):
<?xml version="1.0" encoding="UTF-8"?>
<DataRequest>
<fromDate>2021-11-13T00:09:20.021Z</fromDate>
<toDate>2021-11-13T00:09:20.022Z</toDate>
</DataRequest>
As result, request instance is incorrect - all dates are 01.01.0001 ... (see attached picture "xml serialization in swagger.png")
Obviously, the problem is a incorrect node names - fromDate and toDate. The correct names must be FromDate and ToDate accordingly. The workout is rename these tags manually but much more better to fix the swagger behaviour for XML serialization.
Thanks a lot.
Original Comments
Feedback Bot on 11/14/2021, 11:25 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Feedback Bot on 12/15/2021, 11:52 AM:
This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.