Allow usage of ObjectSerializer for Cosmos bindings#3163
Conversation
0aaa0fd to
1708190
Compare
|
Re-opening. I have reverted back to opt-in for this change. |
There was a problem hiding this comment.
Pull request overview
This PR addresses a regression in the CosmosDB extension where custom JSON serialization settings from WorkerOptions.Serializer were not being used when deserializing POCOs in CosmosDB bindings. The fix introduces a new Serializer property to CosmosDBExtensionOptions and a helper method UseCosmosDBWorkerSerializer() to explicitly opt-in to using the worker's serializer for CosmosDB POCO deserialization.
Key changes:
- Added
ObjectSerializer? Serializerproperty toCosmosDBExtensionOptionsfor custom serialization - Introduced
UseCosmosDBWorkerSerializer()extension method to configure the serializer - Refactored
CosmosDBConverterto use the configured serializer instead of hardcodedSystem.Text.Json - Fixed a bug in
WorkerCosmosSerializer.FromStream()where streams were being disposed prematurely - Maintained backward compatibility via a
DefaultSerializerwithPropertyNameCaseInsensitive = true
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| WorkerCosmosSerializer.cs | Fixed stream disposal bug for Stream-type bindings and minor style improvements |
| FunctionsWorkerApplicationBuilderExtensions.cs | Added UseCosmosDBWorkerSerializer() method and updated serializer configuration logic |
| CosmosDBConverter.cs | Replaced hardcoded System.Text.Json with configurable ObjectSerializer throughout |
| CosmosDBExtensionOptions.cs | Added public Serializer property with TODO for future default behavior |
| CosmosDBBindingOptions.cs | Added DefaultSerializer and Serializer property getter for fallback behavior |
| CosmosDBBindingOptionsSetup.cs | Removed unused import and formatting cleanup |
| release_notes.md | Updated version placeholder and release note description |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
brettsam
left a comment
There was a problem hiding this comment.
No objections to the changes, but would love to see tests added around this, especially since it looks like we broke behavior at one point.
29f7220 to
45f41f3
Compare
|
@brettsam unit tests have been added. I verify the new options setup in one test class, and then added converter tests to verify the resolved serializer is used for the POCO case. |
Issue describing the changes in this PR
resolves #2911
Pull request checklist
release_notes.mdAdditional information
Addresses an issue with CosmosDB extension where users could not customize JSON serialization when binding directly to a POCO.
Issue:
CosmosDBConverterwas not consuming any user-provided JSON serialization customization. This was a regression from #1924.Fix:
CosmosDBExtensionOptionsto provide aObjectSerializer, defaulting toWorkerOptions.Serializerif no serializer is explicitly set.CosmosDBConverterto use this new serializer when deserializing POCOsConcerns / Discussion:
This is a fix for a regression introduced back in December 2023. But it COULD be seen as a new breaking behavior change for some customers. This poses some risk for this change.