How can I send this data by postman?
Adrian Godoy
Asked:
2020-07-26 01:29:17 +0800 CST
Edit: I add array to the Json objects since the real case includes arrays.
I have a class element
that contains a property options
, the options class can in turn change its properties for example it could have these 2
element1 = {
"id":"1",
"options":{
"margenes":["24px","25px","0px","32px"],
"printable":"true",
"stackOverflow":"great"
}
}
element2 = {
"id":"2",
"options":{
"question":"awsome",
"propertyDiferent":"empty"
}
}
In the web api I have a method like this:
public object Post([FromBody] Element element)
{
SaveToMongo(element);
}
the element class:
public class Element
{
public dynamic options { get; set; }
public string id { get; set; }
}
When I fetch the Element from mongo I have no problems. But when I have to send it through the web api's post method it doesn't deserialize into an expando object like it does from mongo. How could I achieve similar behavior on both ends?
Basically I want that the passage of the object through the web api does not involve an effort. I have created the web-api simply because I was not able to attack mongo from javascript.