Skip to content Skip to sidebar Skip to footer

WebApi Doesnt Serialize Null Fields

I've got the following following command in my web api: return Request.CreateResponse(HttpStatusCode.OK, MyDBContext.DB.Database.SqlQuery('SELECT * FROM

Solution 1:

I found the fix was to specify the following in the json formatter serializer settings:

jsonFormatter.SerializerSettings = new JsonSerializerSettings() 
{ 
   NullValueHandling = NullValueHandling.Include 
};

Solution 2:

I don't think that's expected behavior. At least in terms of JSON. I can't speak much about WebAPI, since I haven't used it. In a project of mine that uses JSON, if I were to issue the following code:

# Package our response into an array... 
$response = array("type"=>"remove_from_distribution_list","results");                   

# And send it back to XMLHttpRequest object encoded...       
echo json_encode($response);

with results having no value, results would still be passed along. There would just be no value passed alongside it.


Post a Comment for "WebApi Doesnt Serialize Null Fields"