-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5825: Support (de)serialization between BSON and EJSON #1939
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
base: main
Are you sure you want to change the base?
Changes from all commits
a285da2
6995985
24a2d6e
d40ed65
56582eb
69eab79
f577f29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* 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. | ||
| */ | ||
|
|
||
| namespace MongoDB.Driver | ||
| { | ||
| /// <summary> | ||
| /// Represents the options parameter for <see cref="Mql.DeserializeEJson{TInput, TOutput}(TInput, DeserializeEJsonOptions{TOutput})"/>. | ||
| /// </summary> | ||
| public abstract class DeserializeEJsonOptions | ||
| { | ||
| internal abstract bool OnErrorWasSet(out object onError); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Represents the options parameter for <see cref="Mql.DeserializeEJson{TInput, TOutput}(TInput, DeserializeEJsonOptions{TOutput})"/>. | ||
| /// This class allows setting 'onError'. | ||
| /// </summary> | ||
| /// <typeparam name="TOutput">The type of 'onError'.</typeparam> | ||
| public class DeserializeEJsonOptions<TOutput> : DeserializeEJsonOptions | ||
| { | ||
| private TOutput _onError; | ||
| private bool _onErrorWasSet; | ||
|
|
||
| /// <summary> | ||
| /// The onError parameter. | ||
| /// </summary> | ||
| public TOutput OnError | ||
| { | ||
| get => _onError; | ||
| set | ||
| { | ||
| _onError = value; | ||
| _onErrorWasSet = true; | ||
| } | ||
| } | ||
|
|
||
| internal override bool OnErrorWasSet(out object onError) | ||
| { | ||
| onError = _onError; | ||
| return _onErrorWasSet; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* 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; | ||
| using MongoDB.Driver.Core.Misc; | ||
| using MongoDB.Driver.Linq.Linq3Implementation.Ast.Visitors; | ||
|
|
||
| namespace MongoDB.Driver.Linq.Linq3Implementation.Ast.Expressions | ||
| { | ||
| internal sealed class AstDeserializeEJsonExpression : AstExpression | ||
| { | ||
| private readonly AstExpression _input; | ||
| private readonly AstExpression _onError; | ||
|
|
||
| public AstDeserializeEJsonExpression( | ||
| AstExpression input, | ||
| AstExpression onError = null) | ||
| { | ||
| _input = Ensure.IsNotNull(input, nameof(input)); | ||
| _onError = onError; | ||
| } | ||
|
|
||
| public AstExpression Input => _input; | ||
| public override AstNodeType NodeType => AstNodeType.DeserializeEJsonExpression; | ||
| public AstExpression OnError => _onError; | ||
|
|
||
| public override AstNode Accept(AstNodeVisitor visitor) | ||
| { | ||
| return visitor.VisitDeserializeEJsonExpression(this); | ||
| } | ||
|
|
||
| public override BsonValue Render() | ||
| { | ||
| return new BsonDocument | ||
| { | ||
| { "$deserializeEJSON", new BsonDocument | ||
| { | ||
| { "input", _input.Render() }, | ||
| { "onError", () => _onError.Render(), _onError != null } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| public AstDeserializeEJsonExpression Update( | ||
| AstExpression input, | ||
| AstExpression onError) | ||
| { | ||
| if (input == _input && onError == _onError) | ||
| { | ||
| return this; | ||
| } | ||
|
|
||
| return new AstDeserializeEJsonExpression(input, onError); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* 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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+14
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /* 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. | |
| */ | |
| /* | |
| * 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. | |
| */ |
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.
This seems to be incorrect.
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new methods in this file break the alphabetical ordering. |
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.
The Apache license header formatting here is inconsistent with other files in this directory (e.g.,
AstDateFromStringExpression.csuses*-prefixed lines). Consider aligning the comment formatting to the standard header style used elsewhere to keep license headers uniform.