WebAPI 2.0 Post Not Deserializing List <T> Property
I went through every similar article I can find here and tried anything that looked like it might work without success (obv, since I'm asking the question now).
I have a webAPI 2.0 controller with a POST action that takes an object of type Reservation
. This object contains, among other things, a property Items
that has a type EquipmentItems
. As you can imagine, this is a List property. I am posting a reservation object (using PostAsJsonAsync("api/Reservation", reservation).Result
if it matters to anyone).
When I land in the API controller, the object is Reservation
completely populated with everything except what's in the property EquipmentItems
.
In the spirit of full disclosure, a property Items
in a class Reservation
is actually defined as a List, where T is the interface IItemData
. EquimpentItem
inherits from IItemData
tho, so not sure if that complicates matters.
Can a native controller deserializer not process a list where T is an interface?
What I know works is defining the list as a regular array. This works pretty well, but I have other requirements that have moved me to use List.
Any suggestions on how to properly get this property deserialized?
source to share
Right. If you are trying to deserialize to List<ISomething>
, then it won't work. The reason is that the deserialization operation does not know which ISOM that you want to create (you cannot run ISomething because it is not a specific class). You will need to change the service interface to expose the specific class for the list. (i.e. List<Something>
).
source to share