'Accepting body with generic type
I'm creating a web API that accepts a custom object. This works when someone does a POST
request in JSON
format. But now I have someone asking if they can post in XML
, from my understanding this shouldn't be an issue. However, the body is always null
in my Controller.
public IHttpActionResult SomeMethod([FromBody] StoreModel<object> obj) {
// ... Code
}
The model looks like this:
public class StoreModel<T> {
public T MetaData { get; set; }
public string Name { get; set; }
}
Swagger suggests the following JSON input:
{
"metaData": {},
"name": "string"
}
but for XML it says this:
<?xml version="1.0"?>
<StoreModel[Object]>
<!-- invalid XML -->
<name>string</name>
</StoreModel[Object]>
I tried posting with variations of the swagger suggestion, but nothing seems to be accepted
So I would think some additional configuration is needed?
Solution 1:[1]
Have a look at these 2 URLs:
- Issue with sending XML to Web Api via http Post request. Here notice at:
([FromBody]XElement xml)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mahsan Ghasemi |