Skip to main content

Serialization

ArangoDB C#/.NET driver allows for alternative serializer implementations to be used by implementing the IApiClientSerialization interface or ApiClientSerialization abstract class. The abstract class provides an additional property for default serialization options to use as a fallback when the caller provides none.

By default, all API clients use the provided JsonNetApiClientSerialization, which uses the Json.NET library. To use an alternative serialization implementation, pass an instance of IApiClientSerialization when instantiating any API client class or the ArangoDBClient class.

In many cases, it relied on the behavior of Json.NET to automatically map JSON properties using camelCase to C# properties defined using PascalCase when deserializing. Any alternative serializer must mimic that behavior to deserialize some ArangoDB JSON objects to their C# types. For example, if using System.Text.Json, the option PropertyNameCaseInsensitive = true should be used.

Serialization Options

All API methods that support passing objects of user-specified data types have an optional method argument to pass in custom serialization options. You can use these options to control the behavior of the underlying serializer implementation.

The options are passed as an instance of the ApiClientSerializationOptions class, which contains options for:

  • boolean UseCamelCasePropertyNames
  • boolean IgnoreNullValues

In addition, the default options can be updated, which affects all subsequent operations that use these options. To set default options, set them on the serializer implementation itself. For example, if using the supplied JsonNetApiClientSerialization:

var serializer = new JsonNetApiClientSerialization();
serializer.DefaultOptions.IgnoreNullValues = false;
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback