Conventions: Serialization

CustomizeJsonSerializer

If you need to modify JsonSerializer object used by the client when sending entities to the server you can register a customization action:

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

CustomizeJsonDeserializer

To modify the JsonSerializer object used by the client to deserialize entities loaded from the server, you can register a customization action:

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

DeserializeEntityFromBlittable

In order to customize the entity deserialization from blittable JSON you can use define DeserializeEntityFromBlittable implementation:

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

JsonContractResolver

The default JsonContractResolver used by RavenDB will serialize all properties and all public fields. You can change it by providing own implementation of IContractResolver interface:

Serialization = new NewtonsoftJsonSerializationConventions
{
    JsonContractResolver = new CustomJsonContractResolver()
}

public class CustomJsonContractResolver : IContractResolver
{
    public JsonContract ResolveContract(Type type)
    {
        throw new CodeOmitted();
    }
}

You can also customize behavior of the default resolver by inheriting from DefaultRavenContractResolver and overriding specific methods.

public class CustomizedRavenJsonContractResolver : DefaultRavenContractResolver
{
    public CustomizedRavenJsonContractResolver(ISerializationConventions conventions) : base(conventions)
    {
    }

    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
    {
        throw new CodeOmitted();
    }
}

PreserveDocumentPropertiesNotFoundOnModel

Controls whatever properties that were not de-serialized to an object properties will be preserved during saving a document again. If false, those properties will be removed when the document will be saved. Default: true.

PreserveDocumentPropertiesNotFoundOnModel = true

BulkInsert.TrySerializeEntityToJsonStream

For the bulk insert you can configure custom serialization implementation by providing TrySerializeEntityToJsonStream:

BulkInsert =
{
    TrySerializeEntityToJsonStream = (entity, metadata, writer) => throw new CodeOmitted(),
}

Numbers (de)serialization

RavenDB client supports out of the box all common numeric value types: int, long, double, decimal etc.
Note that although the (de)serialization of decimals is fully supported, there are server side limitations to numbers in that range.
Other number types like BigInteger must be treated using custom (de)serialization.

IgnoreByRefMembers and IgnoreUnsafeMembers

By default, if you try to store an entity that has ref or unsafe members, the Client will throw an exception when session.SaveChanges() is called.

If IgnoreByRefMembers is set to true and you try to store an entity that has ref members, those members will simply be ignored. The entity will be uploaded to the server with all non-ref members without throwing an exception. The document structure on the server-side will not contain fields for those ref members.

If IgnoreUnsafeMembers is set to true, all pointer members will be ignored in the same manner.

The default value of both these conventions is false.