RestSharp: How to skip serializing null values to JSON?

Bryan picture Bryan · Nov 15, 2013 · Viewed 8k times · Source

RestSharp's built-in JSON serializer serializes all of an object's properties, even if they're null or otherwise the default value. How can I make it skip these properties?

Answer

leo1987 picture leo1987 · Apr 21, 2015

An alternative, you can use other json libraries (json.net, servicestack.text, etc.) which support ignoring null values to serialize it first:

RestRequest request = new RestRequest();
...
string jsonString = ThirdPartySerialization(jsonObject);
request.AddParameter("application/json", jsonString, ParameterType.RequestBody);