I am doing a C# web Api Method and the Consumer.
Firstly, the method retrieve a class instance and the Consumer call it like this, and parse it to a Class called R
HttpResponseMessage response = client.PostAsJsonAsync(url, param).Result;
R value = await response.Content.ReadAsJsonAsync<R>();
Now, I need to retrieve from my Api, only the class properties it have data. For that reason it parse the class instance to Json, as i asked here, using
string jsonIgnoreNullValues = JsonConvert.SerializeObject(response, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
My web Method definition is simple
public IHttpActionResult Newemployee([FromBody] RequestManual items)
{
ResponseManual response = Service.Newemployee(items.Datos);
//Before
return Ok(response);
//Now
string jsonIgnoreNullValues = JsonConvert.SerializeObject(response, Formatting.Indented, new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
});
return Ok(jsonIgnoreNullValues);
}
}
.NET automatically Serialize to Json in the response, When i Serialize the response to avoid null properties, the respose is getting serialized twice...
How can avoid this, or how can I read this?
Thanks