CSHARP-5846: Global GuidSerializer settings ignored for object-typed properties#1990
CSHARP-5846: Global GuidSerializer settings ignored for object-typed properties#1990papafe wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Updates ObjectSerializer so that when constructed with GuidRepresentation.Unspecified, it will use the globally registered Guid serializer (instead of always creating its own GuidSerializer(Unspecified)), addressing CSHARP-5846 (“global GuidSerializer settings ignored for object-typed properties”). Adds regression tests validating serialization and deserialization behavior using a temporarily substituted global GuidSerializer.
Changes:
ObjectSerializernow resolves_guidSerializerfromBsonSerializer.LookupSerializer<Guid>()whenguidRepresentationisUnspecified.- Added tests ensuring object-typed Guid values use the globally registered Guid serializer for UUID legacy representation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/MongoDB.Bson/Serialization/Serializers/ObjectSerializer.cs |
Uses the globally registered Guid serializer when guidRepresentation is Unspecified. |
tests/MongoDB.Bson.Tests/Serialization/Serializers/ObjectSerializerTests.cs |
Adds regression tests covering global Guid serializer usage for object-typed Guid serialization/deserialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var registeredSerializer = BsonSerializer.LookupSerializer<Guid>(); | ||
| if (registeredSerializer is GuidSerializer guidSerializer) | ||
| { | ||
| _guidSerializer = guidSerializer; | ||
| _guidRepresentation = guidSerializer.GuidRepresentation; | ||
| } | ||
| else | ||
| { | ||
| _guidRepresentation = GuidRepresentation.Unspecified; | ||
| _guidSerializer = registeredSerializer; | ||
| } |
| result.Should().Be(guid); | ||
| } | ||
|
|
||
| private static ObjectSerializer CreateObjectSerializerWithRegisteredGuidSerializer( |
There was a problem hiding this comment.
I'm curious about what the team thinks about this. Unfortunately without having a local serialization registry, we can't test this properly otherwise.
| var registeredSerializer = BsonSerializer.LookupSerializer<Guid>(); | ||
| if (registeredSerializer is GuidSerializer guidSerializer && guidSerializer.GuidRepresentation != GuidRepresentation.Unspecified) | ||
| { | ||
| _guidSerializer = guidSerializer; | ||
| _guidRepresentation = guidSerializer.GuidRepresentation; | ||
| } | ||
| else | ||
| { | ||
| _guidRepresentation = GuidRepresentation.Unspecified; | ||
| _guidSerializer = new GuidSerializer(GuidRepresentation.Unspecified); | ||
| } |
| if (registered is GuidSerializer gs && gs.GuidRepresentation != GuidRepresentation.Unspecified) | ||
| { | ||
| return gs; |
No description provided.