-
Notifications
You must be signed in to change notification settings - Fork 526
CF/P AVAD: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json #4618
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
Merged
microsoft-github-policy-service
merged 23 commits into
master
from
4616-cfp-avad-issues-with-serializationdeserialization-with-cosmossystemtextjsonserializer-and-custom-serializers
Aug 21, 2024
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2216d83
checkin in
philipthomas-MSFT 28d7222
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
philipthomas-MSFT 5f7bc3f
support for both STJ and NSJ
philipthomas-MSFT c5a09e9
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT 3a879b7
update contracts.
philipthomas-MSFT 23e7631
name change PreviousLsn
philipthomas-MSFT 82bc224
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT 375236c
STJ TypeConverter support for ChangeFeedMetadata
philipthomas-MSFT 7acac4d
adding bacl StringEnumConverter
philipthomas-MSFT 461e1e8
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT 6a71a82
test for Writes ChangeFeedMetadata
philipthomas-MSFT b6fde92
removing DateTimeOffset as results are inconsistent.
philipthomas-MSFT f2d1e6f
trying to get GMT, not local
philipthomas-MSFT 84fdcc3
static UnixEpoch
philipthomas-MSFT 2c07550
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
ealsur e868ba5
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
philipthomas-MSFT 7ef00af
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT d71b8b0
Merge branch '4616-cfp-avad-issues-with-serializationdeserialization-…
philipthomas-MSFT d30e7af
static qualifier in tests
philipthomas-MSFT 121d459
PropertyNameCaseInsensitive = false tests. copy of True tests.
philipthomas-MSFT 0339f16
setting PropertyNameCaseInsensitive correctly for tests
philipthomas-MSFT 3b13a15
removed duplication for propertyNameCaseInsensitive tests
philipthomas-MSFT 625fe86
remove JsonStringEnumConverter(), from tests
philipthomas-MSFT 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
15 changes: 15 additions & 0 deletions
15
Microsoft.Azure.Cosmos/src/Resource/FullFidelity/ChangeFeedMetadataFields.cs
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,15 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Resource.FullFidelity | ||
| { | ||
| internal class ChangeFeedMetadataFields | ||
| { | ||
| public const string ConflictResolutionTimestamp = "crts"; | ||
| public const string Lsn = "lsn"; | ||
| public const string OperationType = "operationType"; | ||
| public const string PreviousImageLSN = "previousImageLSN"; | ||
| public const string TimeToLiveExpired = "timeToLiveExpired"; | ||
| } | ||
| } |
92 changes: 92 additions & 0 deletions
92
Microsoft.Azure.Cosmos/src/Resource/FullFidelity/Converters/ChangeFeedMetadataConverter.cs
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,92 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
|
|
||
| namespace Microsoft.Azure.Cosmos.Resource.FullFidelity.Converters | ||
| { | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
| using Microsoft.Azure.Cosmos.Resource.FullFidelity; | ||
| using Microsoft.Azure.Documents; | ||
|
|
||
| /// <summary> | ||
| /// Converter used to support System.Text.Json de/serialization of type ChangeFeedMetadata/>. | ||
| /// </summary> | ||
| internal class ChangeFeedMetadataConverter : JsonConverter<ChangeFeedMetadata> | ||
| { | ||
| private readonly static DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); | ||
|
|
||
| public override ChangeFeedMetadata Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType == JsonTokenType.Null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (reader.TokenType != JsonTokenType.StartObject) | ||
| { | ||
| throw new JsonException(string.Format(CultureInfo.CurrentCulture, RMResources.JsonUnexpectedToken)); | ||
| } | ||
|
|
||
| JsonElement element = JsonDocument.ParseValue(ref reader).RootElement; | ||
|
|
||
| ChangeFeedMetadata metadata = new (); | ||
|
|
||
| foreach (JsonProperty property in element.EnumerateObject()) | ||
| { | ||
| if (property.NameEquals(ChangeFeedMetadataFields.Lsn)) | ||
| { | ||
| metadata.Lsn = property.Value.GetInt64(); | ||
| } | ||
| else if (property.NameEquals(ChangeFeedMetadataFields.ConflictResolutionTimestamp)) | ||
| { | ||
| metadata.ConflictResolutionTimestamp = ChangeFeedMetadataConverter.ToDateTimeFromUnixTimeInSeconds(property.Value.GetInt64()); | ||
| } | ||
| else if (property.NameEquals(ChangeFeedMetadataFields.OperationType)) | ||
| { | ||
| metadata.OperationType = (ChangeFeedOperationType)Enum.Parse(enumType: typeof(ChangeFeedOperationType), value: property.Value.GetString(), ignoreCase: true); | ||
| } | ||
| else if (property.NameEquals(ChangeFeedMetadataFields.TimeToLiveExpired)) | ||
| { | ||
| metadata.IsTimeToLiveExpired = property.Value.GetBoolean(); | ||
| } | ||
| else if (property.NameEquals(ChangeFeedMetadataFields.PreviousImageLSN)) | ||
| { | ||
| metadata.PreviousLsn = property.Value.GetInt64(); | ||
| } | ||
| } | ||
|
|
||
| return metadata; | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, ChangeFeedMetadata value, JsonSerializerOptions options) | ||
| { | ||
| if (value == null) | ||
philipthomas-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return; | ||
| } | ||
|
|
||
| writer.WriteStartObject(); | ||
|
|
||
| writer.WriteNumber(ChangeFeedMetadataFields.ConflictResolutionTimestamp, ChangeFeedMetadataConverter.ToUnixTimeInSecondsFromDateTime(value.ConflictResolutionTimestamp)); | ||
| writer.WriteBoolean(ChangeFeedMetadataFields.TimeToLiveExpired, value.IsTimeToLiveExpired); | ||
| writer.WriteNumber(ChangeFeedMetadataFields.Lsn, value.Lsn); | ||
| writer.WriteString(ChangeFeedMetadataFields.OperationType, value.OperationType.ToString()); | ||
| writer.WriteNumber(ChangeFeedMetadataFields.PreviousImageLSN, value.PreviousLsn); | ||
|
|
||
| writer.WriteEndObject(); | ||
| } | ||
|
|
||
| private static long ToUnixTimeInSecondsFromDateTime(DateTime date) | ||
| { | ||
| return (long)(date - ChangeFeedMetadataConverter.UnixEpoch).TotalSeconds; | ||
| } | ||
|
|
||
| private static DateTime ToDateTimeFromUnixTimeInSeconds(long unixTimeInSeconds) | ||
| { | ||
| return ChangeFeedMetadataConverter.UnixEpoch.AddSeconds(unixTimeInSeconds); | ||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.