Azure / azure-cosmos-dotnet-v2

Contains samples and utilities relating to the Azure Cosmos DB .NET SDK
MIT License
577 stars 838 forks source link

Expose the JSON serialization settings. #229

Closed Jabronironi closed 7 years ago

Jabronironi commented 7 years ago

There is a community suggestion with almost 850 votes regarding this, but I just noticed there is no actual issue related to it open. That surprised me. The fact there is no convenient way to change the JSON serialization settings (without affecting the default behavior of your entire app), is causing a lot of people pain.

Edit: Now close to 950 votes.

mcbridedm commented 7 years ago

Please PLEASE get on this feature. It seems rather ridiculous to not be there already.

BowserKingKoopa commented 7 years ago

Still struggling with this.

benaiahjohn commented 7 years ago

Please do this ASAP. Need this badly

BowserKingKoopa commented 7 years ago

I've had to wrap the DocumentDB api and wrest control of serialization away from it completely in order to get my objects to serialize/deserialize the way I want. And the api fights you the whole way because it really wants to be the one to do the serialization.

kieronlanning commented 7 years ago

+1

carlos-sarmiento commented 7 years ago

+1

bergey commented 7 years ago

The other thread mentioned by the OP seems to be https://feedback.azure.com/forums/263030-documentdb/suggestions/6422364-allow-me-to-set-jsonserializersettings

Jabronironi commented 7 years ago

Yes, thank you. Not sure why I didn't post the link when I mentioned it. Bad OP.

nhwilly commented 7 years ago

me, too. me, too.

rnagpal commented 7 years ago

We are currently working on this.

nhwilly commented 7 years ago

Great news!!!

ahmedabadawi commented 7 years ago

As a workaround, I had to wrap the entity being saved in another object with public accessors for the properties needed for searching and save the entity as a string serialized with a custom JSON Serialization options to allow instantiation from a private constructor or use private setters

mcbridedm commented 7 years ago

The sdk can return doc as string directly

On May 10, 2017 11:11 AM, "Ahmed Badawi" notifications@github.com wrote:

As a workaround, I had to wrap the entity being saved in another object with public accessors for the properties needed for searching and save the entity as a string serialized with a custom JSON Serialization options to allow instantiation from a private constructor or use private setters

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Azure/azure-documentdb-dotnet/issues/229#issuecomment-300567592, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEbov505xrEaS3jZTCfGpUjLesH_BVeks5r4f3MgaJpZM4MkhWo .

ahmedabadawi commented 7 years ago

The use-case I was working on, is that I want to search by two attributes on the document and retrieve the whole document matching those criteria. So basically I made a wrapper class that exposes the two attributes used in the search and serialized the rest of the document as string inside that wrapper document

kieronlanning commented 7 years ago

How far away is this at the moment? Struggling without custom JSON serialization options at the moment.

acollard commented 7 years ago

Looks like this is now in 1.15.0 for .Net Framework. https://docs.microsoft.com/en-us/azure/cosmos-db/documentdb-sdk-dotnet#release-notes

Hoping this makes it into .Net Core soon.

Liversage commented 7 years ago

In the Microsoft.Azure.DocumentDB 1.15.0 NuGet package you can now provide your own JsonSerializerSettings when creating a DocumentClient. 👏

However, I ran into a problem and as there seem to be no good way to report CosmosDB issues I instead provide the information here as it might be useful to someone else.

If your document class derives from Microsoft.Azure.Documents.Document then the provided JsonSerializerSettings will NOT be used for serialization and deserialization.

Additionally, I have discovered that if I use CamelCasePropertyNamesContractResolver in the JsonSerializerSettings then LINQ queries will fail because the JSON property name starts with a lower case letter while the C# property name starts with an upper case letter (C# classes used in queries have pascal cased property names as usual).

kieronlanning commented 7 years ago

This is now a closed issue according to UserVoice (https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/6422364-allow-me-to-set-jsonserializersettings?tracking_code=416a22ac7904c38f34440fe7c6ee9e55).

I've tried e-mailing the team, leaving feedback, but no-one is getting back to me on when the .NET Core version will get this support.

At this point, I'm having to move away from DocumentDb.

rnagpal commented 7 years ago

@kieronlanning We have fixed this for .NET Core and will be doing a releasing in next few days.

kieronlanning commented 7 years ago

Splendid, thanks @rnagpal.

rnagpal commented 7 years ago

@kieronlanning This is part of .NET Core 1.4.0 released today.

@Liversage : I'm closing this issue as this tracked the support of JsonSerializerSettings in the SDK. Would you mind creating a separate issue for the bug you found so that it can be tracked separately?

kieronlanning commented 7 years ago

That's great - updated and it's working as it's expected.

Thanks @rnagpal.