Skip to content

Setting both Custom Serializer and SerializationOptions in CosmosClientOptions #2212

Closed

Description

Current Model

Currently only one of the options, Serializer or SerializerOptions can be set in CosmosClientOptions while creating the CosmosClient. This is not allowed and throws a BadRequest (400)

new CosmosClientOptions
{
    ConnectionMode = ConnectionMode.Gateway,
    SerializerOptions = new CosmosSerializationOptions
    {
        PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase
    },
    Serializer = new MyNewCustomSerializer()
}
  • LINQ query generation only uses SerializerOptions. This creates a problem when the user wants to specify a Custom Serializer.

Option 1

  • Allow user to set both SerializerOptions and Serializer Property. LINQ will use the SerializerOptions provided and other operations will use the custom serializer.
  • It is up to the user to make sure that the 2 are in sync.

Option 2

We add a public property in CosmosSerializer for providing SerializerOptions

public abstract class CosmosSerializer
{
    public abstract CosmosSerializationOptions serializerOptions;
    public abstract T FromStream<T>(Stream stream);
    public abstract Stream ToStream<T>(T input);
}
  • We only allow one of the SerializerOptions to be set between CosmosSerializer and CosmosClientOptions.
  • This tells the user that he needs to change this setting based on his CustomSerializer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions