Skip to content

CSHARP-5846: Global GuidSerializer settings ignored for object-typed properties#1990

Open
papafe wants to merge 5 commits into
mongodb:mainfrom
papafe:csharp5846
Open

CSHARP-5846: Global GuidSerializer settings ignored for object-typed properties#1990
papafe wants to merge 5 commits into
mongodb:mainfrom
papafe:csharp5846

Conversation

@papafe
Copy link
Copy Markdown
Contributor

@papafe papafe commented May 7, 2026

No description provided.

@papafe papafe requested a review from a team as a code owner May 7, 2026 09:21
Copilot AI review requested due to automatic review settings May 7, 2026 09:21
@papafe papafe added the bug Fixes issues or unintended behavior. label May 7, 2026
@papafe papafe requested a review from adelinowona May 7, 2026 09:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • ObjectSerializer now resolves _guidSerializer from BsonSerializer.LookupSerializer<Guid>() when guidRepresentation is Unspecified.
  • 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.

Comment on lines +147 to +157
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(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about what the team thinks about this. Unfortunately without having a local serialization registry, we can't test this properly otherwise.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +147 to +157
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);
}
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +150 to +152
if (registered is GuidSerializer gs && gs.GuidRepresentation != GuidRepresentation.Unspecified)
{
return gs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Fixes issues or unintended behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants