- Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-3985: Serialization config objects belong to a serialization domain #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rstam wants to merge 15 commits into mongodb:main Choose a base branch from rstam:csharp3985-rstam
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits Select commit Hold shift + click to select a range
0472c3d
Merge
papafe 0595cb8
small correction
papafe d83811d
Lazy inizialization of DiscriminatedInterfaceSerializer
papafe ef988c3
Small corrections-adjustements.
papafe 879f6c5
Small fix
papafe 43ea9c2
Added missing check.
papafe 08247aa
Small fixes
papafe a8ba088
Small fixes
papafe 59c3a47
Removed unnecessary comments.
papafe 27671ae
Fixed BsonDocumentWrapper and added comments
papafe f8915ab
Removed docs and make some methods private
papafe 7f45484
Small corrections
papafe acd8a64
Removed other comments.
papafe a541b08
CSHARP-3985: POC with configuration objects belonging to a serializat…
rstam 76665ec
Fix some tests and throw an exception when trying to register an obje…
rstam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
| ||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
using MongoDB.Bson.Serialization; | ||
| ||
namespace MongoDB.Bson | ||
{ | ||
internal class BsonDefaultsRegistry : IBsonDefaults | ||
{ | ||
private IBsonSerializationDomain _serializationDomain; | ||
private bool _dynamicArraySerializerWasSet; | ||
private IBsonSerializer _dynamicArraySerializer; | ||
private bool _dynamicDocumentSerializerWasSet; | ||
private IBsonSerializer _dynamicDocumentSerializer; | ||
| ||
public BsonDefaultsRegistry(IBsonSerializationDomain serializationDomain) | ||
{ | ||
_serializationDomain = serializationDomain; | ||
} | ||
| ||
public IBsonSerializer DynamicArraySerializer | ||
{ | ||
get | ||
{ | ||
if (!_dynamicArraySerializerWasSet) | ||
{ | ||
_dynamicArraySerializer = _serializationDomain.LookupSerializer<List<object>>(); | ||
} | ||
return _dynamicArraySerializer; | ||
} | ||
set | ||
{ | ||
_dynamicArraySerializerWasSet = true; | ||
_dynamicArraySerializer = value; | ||
} | ||
} | ||
| ||
public IBsonSerializer DynamicDocumentSerializer | ||
{ | ||
get | ||
{ | ||
if (!_dynamicDocumentSerializerWasSet) | ||
{ | ||
_dynamicDocumentSerializer = _serializationDomain.LookupSerializer<ExpandoObject>(); | ||
} | ||
return _dynamicDocumentSerializer; | ||
} | ||
set | ||
{ | ||
_dynamicDocumentSerializerWasSet = true; | ||
_dynamicDocumentSerializer = value; | ||
} | ||
} | ||
| ||
public int MaxDocumentSize { get; set; } = int.MaxValue; | ||
| ||
public int MaxSerializationDepth { get; set; } = 100; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright 2010-present MongoDB Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
| ||
using MongoDB.Bson.Serialization; | ||
| ||
namespace MongoDB.Bson | ||
{ | ||
internal interface IBsonDefaults | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
IBsonSerializer DynamicArraySerializer { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
IBsonSerializer DynamicDocumentSerializer { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
int MaxDocumentSize { get; set; } | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
int MaxSerializationDepth { get; set; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 fromBsonDefaults
anyway, in actual use it is determined by the max document size the server tells us to use.There was a problem hiding this comment.
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
andMaxSerializationDepth
.Do you think they should all be removed from the defaults?
Giving a brief look it seems that
DynamicArraySerializer
andDynamicDocumentSerializer
are quite circumstantial and used only byObjectSerializer
andExpandoObjectSerializer
. Maybe they should be configuration options on those serializers instead?MaxDocumentSize
you already said it should be removed from the defaults, what aboutMaxSerializationDepth
?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?