Skip to main content

Conventions: Deserialization

CustomizeJsonDeserializer​

  • The client uses JsonSerializer objects of the Newtonsoft.Json library to deserialize documents loaded from the server into entities.
  • Use the CustomizeJsonDeserializer convention to register an action that modifies only the JsonSerializer objects used to load documents (e.g., to keep a property's default value when the loaded document holds null for this property).

    Conventions =
    {
    Serialization = new NewtonsoftJsonSerializationConventions
    {
    CustomizeJsonDeserializer = serializer => throw new CodeOmitted()
    }
    }

  • Note that an action registered using CustomizeJsonSerializer also applies when loading documents, and runs before the CustomizeJsonDeserializer action.
    A converter registered using CustomizeJsonSerializer therefore does not need to be registered using CustomizeJsonDeserializer as well.

DeserializeEntityFromBlittable​

Use the DeserializeEntityFromBlittable convention to customize entity deserialization from a blittable JSON.

Conventions =
{
Serialization = new NewtonsoftJsonSerializationConventions
{
DeserializeEntityFromBlittable = (type, blittable) => throw new CodeOmitted()
}
}

PreserveDocumentPropertiesNotFoundOnModel​

  • Some document properties are not deserialized to an object.
  • Set the PreserveDocumentPropertiesNotFoundOnModel convention to true to preserve such properties when the document is saved.
  • Set the PreserveDocumentPropertiesNotFoundOnModel convention to false to remove such properties when the document is saved.
  • Default: true
Conventions =
{
PreserveDocumentPropertiesNotFoundOnModel = true
}

DefaultRavenSerializationBinder​

Use the DefaultRavenSerializationBinder convention and its methods to prevent gadgets from running RCE (Remote Code Execution) attacks while data is deserialized by the client.

Read about this security convention and maintaining deserialization security here.

Number Deserialization​

  • RavenDB client supports all common numeric value types (including int, long, double, decimal, etc.) out of the box.
  • Note that although deserialization of decimals is fully supported, there are server side limitations to numbers in this range.
  • Other number types, like BigInteger, must be handled using a converter.

In this article