Skip to content

Conversation

rstam
Copy link
Contributor

@rstam rstam commented Sep 18, 2025

No description provided.

@rstam rstam requested a review from a team as a code owner September 18, 2025 03:43
@rstam rstam requested review from ajcvickers and removed request for a team and ajcvickers September 18, 2025 03:43
@rstam rstam changed the title Csharp3985 rstam CSHARP-3985: Serialization config objects belong to a serialization domain Sep 18, 2025
@rstam rstam added the chore Label to hide PR from generated Release Notes label Sep 18, 2025
…ct in one domain that belongs to a different domain.
Copy link
Contributor

@papafe papafe left a comment

Choose a reason for hiding this comment

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

Overall it looks very good and I also really like that it's a much slimmer PR.

I like the direction, and I would like to try to make some example domain-construction/building API to explore how a developer would build it.

I think that it would be a nice API, if we manage to create the domain starting from serializers/conventions/etc instead of viceversa, but I'll explore that.

return serializer.Deserialize(context, args);
}

internal static IBsonSerializer GetSerializerForBaseType(this IBsonSerializer serializer, Type baseType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not yet...

This is somewhat orthogonal to serialization domains and could be postponed and done later.

The idea is that we should always ask the serializer FIRST for the related base or derived type serializer rather than just looking it up in the registry. That would allow a family of polymorphic serializers to work together properly without using the registry.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! Yes, probably we should do it separately, so we don't put more irons on the fire.

/// </summary>
public static IBsonSerializationDomain Default => __default;

internal static IBsonSerializationDomain Create(string name)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not used, but also I suppose that a completely "empty" domain without defaults is not useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hard to say. If I wanted to create a fully customized serialization domain from scratch I wouldn't want it to be polluted with all the defaults.

Copy link
Contributor

Choose a reason for hiding this comment

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

True, I still think it's a very daunting task to create a domain completely from the ground up.

}
else
{
var bsonDefaults = BsonSerializationDomain.Default.BsonDefaults;
Copy link
Contributor

@papafe papafe Oct 16, 2025

Choose a reason for hiding this comment

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

How can we inject the domain here so that we don't refer to the static defaults?

This is a problem in general with the properties of BsonDefaults.

private bool _fixOldBinarySubTypeOnInput = true;
private bool _fixOldDateTimeMaxValueOnInput = true;
private int _maxDocumentSize = BsonDefaults.MaxDocumentSize;
private int _maxDocumentSize = BsonSerializationDomain.Default.BsonDefaults.MaxDocumentSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

How can we inject the domain here?

Copy link
Contributor Author

@rstam rstam Oct 16, 2025

Choose a reason for hiding this comment

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

I think we should not bother to put BsonDefaults into the domain.

The MaxDocumentSize shouldn't be coming from BsonDefaults anyway, in actual use it is determined by the max document size the server tells us to use.

Copy link
Contributor

Choose a reason for hiding this comment

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

We got 4 properties in BsonDefaults at the moment: DynamicArraySerializer, DynamicDocumentSerializer, MaxDocumentSize and MaxSerializationDepth.
Do you think they should all be removed from the defaults?
Giving a brief look it seems that DynamicArraySerializer and DynamicDocumentSerializer are quite circumstantial and used only by ObjectSerializer and ExpandoObjectSerializer. Maybe they should be configuration options on those serializers instead?
MaxDocumentSize you already said it should be removed from the defaults, what about MaxSerializationDepth?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think MaxSerializationDepth can be left global. It doesn't seem like it would need to vary by serialization domain.

I wouldn't remove it entirely though. We need a limit to prevent infinite recursion if someone attempts to serialize a circular structure.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree we can't simply remove MaxSerializationDepth, not sure we should leave it as global, but we can decide later about it.
Regarding the two DynamicArraySerializer/ DynamicDocumentSerializer, do you also agree we could move them to the respective serializers where they are needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Label to hide PR from generated Release Notes

2 participants