Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose default implementation of CosmosSerializer #1813

Closed
ankitvijay opened this issue Aug 28, 2020 · 5 comments
Closed

Expose default implementation of CosmosSerializer #1813

ankitvijay opened this issue Aug 28, 2020 · 5 comments
Labels
API_REVIEW customer-reported Issue created by a customer discussion-wanted Need a discussion on an area

Comments

@ankitvijay
Copy link

ankitvijay commented Aug 28, 2020

Is your feature request related to a problem? Please describe.
The CosmosSerializer class in ComsosDb is currently abstract and all its implementation such as CosmosJsonDotNetSerializer or CosmosTextJsonSerializer are internal sealed. This makes it impossible to extend these serializers in our code. More often than not, we have a need to implement CosmosSerializer in our code. Since there is no default implementation of CosmosSerializer we end up duplicating the ComsosDb SDK internal serializer in our own class.

For example, currently, the only way to supply Newtonsoft JsonSerializerSettings is to implement CosmosSerializer while our only intention is to add custom JsonConverter and initialize properties such as TypeNameHandling, ConstructorHandling, etc.

In addition to this, a default implementation of CosmosSerializer where it gives access to raw JObject/ Stream in derived class can be very useful. In my current project, our custom implementation of CosmosSerializer enables us to do the following things:

  • Run schema migrations/ changes on CosmosDocument after it is read from CosmosDB and before it gets deserialized into the C# entity.

From my experience, CosmosDb does not have a great story to tell when it comes to schema migration/ change on rehydration from CosmosDb. A default implementation of CosmosSerializer may just open the door to achieve equivalent to RavenDb events in future.

  • Decorate Cosmos document with additional properties such as ttl (while running tests) before saving it to Cosmos.

Describe the solution you'd like

Expose default implementation of CosmosSerializer for Newtonsoft.Json and System.Text.Json.

Here is one example of how we could benefit from the default implementation of CosmosSerializer while creating ComsosClient:

public class CustomCosmosSerializerSettings : JsonSerializerSettings
{
   public CustomCosmosSerializerSettings ()
   {
      // Set Converts, TypeNameHandling etc.
   }
}


var cosmosClient = new CosmosClient(serviceEndpoint, authKey,
                new CosmosClientOptions
                {
                    Serializer = new CosmosDefaultSerializer(new CustomCosmosSerializerSettings()),
                });  // CosmosDefaultSerializer comes from CosmosSDK

Describe alternatives you've considered
Create our own custom implementation of CosmosSerializer inspired by CosmosJsonDotNetSerializer or CosmosTextJsonSerializer

@j82w j82w added customer-reported Issue created by a customer discussion-wanted Need a discussion on an area API_REVIEW labels Aug 28, 2020
@j82w
Copy link
Contributor

j82w commented Aug 28, 2020

@kirankumarkolli do you see any issue with this? I don't see any reason for it not to be exposed. Even in v4 SDK there will need a easy way for user to plug in Newtonsoft, and I don't see that as a blocker for the v3 SDK.

@scottluskcis
Copy link

Created discussion 2064 in hopes to generate some new discussion on this topic

@ghost
Copy link

ghost commented Dec 15, 2021

Closing due to in-activity, pease feel free to re-open.

@hades200082
Copy link

Still an issue.

@bartelink
Copy link
Contributor

@hades200082 Put notes on #4330 or #4332 if you have specific needs that are not covered by the recent addition of support for STJ name attributes etc

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API_REVIEW customer-reported Issue created by a customer discussion-wanted Need a discussion on an area
Projects
None yet
Development

No branches or pull requests

5 participants