Skip to content
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

CF/P AVAD: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json #4618

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2216d83
checkin in
philipthomas-MSFT Aug 1, 2024
28d7222
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
philipthomas-MSFT Aug 1, 2024
5f7bc3f
support for both STJ and NSJ
philipthomas-MSFT Aug 5, 2024
c5a09e9
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT Aug 5, 2024
3a879b7
update contracts.
philipthomas-MSFT Aug 5, 2024
23e7631
name change PreviousLsn
philipthomas-MSFT Aug 5, 2024
82bc224
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT Aug 6, 2024
375236c
STJ TypeConverter support for ChangeFeedMetadata
philipthomas-MSFT Aug 6, 2024
7acac4d
adding bacl StringEnumConverter
philipthomas-MSFT Aug 6, 2024
461e1e8
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT Aug 6, 2024
6a71a82
test for Writes ChangeFeedMetadata
philipthomas-MSFT Aug 6, 2024
b6fde92
removing DateTimeOffset as results are inconsistent.
philipthomas-MSFT Aug 7, 2024
f2d1e6f
trying to get GMT, not local
philipthomas-MSFT Aug 7, 2024
84fdcc3
static UnixEpoch
philipthomas-MSFT Aug 7, 2024
2c07550
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
ealsur Aug 12, 2024
e868ba5
Merge branch 'master' into 4616-cfp-avad-issues-with-serializationdes…
philipthomas-MSFT Aug 14, 2024
7ef00af
Merge remote-tracking branch 'origin/master' into 4616-cfp-avad-issue…
philipthomas-MSFT Aug 16, 2024
d71b8b0
Merge branch '4616-cfp-avad-issues-with-serializationdeserialization-…
philipthomas-MSFT Aug 16, 2024
d30e7af
static qualifier in tests
philipthomas-MSFT Aug 16, 2024
121d459
PropertyNameCaseInsensitive = false tests. copy of True tests.
philipthomas-MSFT Aug 19, 2024
0339f16
setting PropertyNameCaseInsensitive correctly for tests
philipthomas-MSFT Aug 19, 2024
3b13a15
removed duplication for propertyNameCaseInsensitive tests
philipthomas-MSFT Aug 19, 2024
625fe86
remove JsonStringEnumConverter(), from tests
philipthomas-MSFT Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Microsoft.Azure.Cosmos
{
using System.Text.Json.Serialization;
using Newtonsoft.Json;

/// <summary>
Expand Down Expand Up @@ -59,18 +60,21 @@ class ChangeFeedItem<T>
/// The full fidelity change feed current item.
/// </summary>
[JsonProperty(PropertyName = "current")]
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
[JsonPropertyName("current")]
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
public T Current { get; set; }

/// <summary>
/// The full fidelity change feed metadata.
/// </summary>
[JsonProperty(PropertyName = "metadata", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("metadata")]
public ChangeFeedMetadata Metadata { get; set; }

/// <summary>
/// For delete operations, previous image is always going to be provided. The previous image on replace operations is not going to be exposed by default and requires account-level or container-level opt-in.
/// </summary>
[JsonProperty(PropertyName = "previous", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("previous")]
public T Previous { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
namespace Microsoft.Azure.Cosmos
{
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Azure.Documents;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

/// <summary>
/// The metadata of a change feed resource with <see cref="ChangeFeedMode"/> is initialized to <see cref="ChangeFeedMode.AllVersionsAndDeletes"/>.
Expand All @@ -16,39 +17,66 @@ namespace Microsoft.Azure.Cosmos
public
#else
internal
#endif
#endif
class ChangeFeedMetadata
{
/// <summary>
/// New instance of meta data for <see cref="ChangeFeedItem{T}"/> created.
/// </summary>
/// <param name="conflictResolutionTimestamp"></param>
/// <param name="lsn"></param>
/// <param name="operationType"></param>
/// <param name="previousLSN"></param>
/// <param name="isTimeToLiveExpired"></param>
public ChangeFeedMetadata(
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
DateTime conflictResolutionTimestamp,
long lsn,
ChangeFeedOperationType operationType,
long previousLSN,
bool isTimeToLiveExpired)
{
this.ConflictResolutionTimestamp = conflictResolutionTimestamp;
this.Lsn = lsn;
this.OperationType = operationType;
this.PreviousLSN = previousLSN;
this.IsTimeToLiveExpired = isTimeToLiveExpired;
}

/// <summary>
/// The conflict resolution timestamp.
/// </summary>
kirankumarkolli marked this conversation as resolved.
Show resolved Hide resolved
[JsonProperty(PropertyName = "crts", NullValueHandling = NullValueHandling.Ignore)]
[JsonConverter(typeof(UnixDateTimeConverter))]
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
public DateTime ConflictResolutionTimestamp { get; internal set; }
ealsur marked this conversation as resolved.
Show resolved Hide resolved
[JsonPropertyName("crts")]
[Newtonsoft.Json.JsonConverter(typeof(UnixDateTimeConverter))]
[System.Text.Json.Serialization.JsonConverter(typeof(Resource.FullFidelity.Converters.STJUnixDateTimeConverter))]
public DateTime ConflictResolutionTimestamp { get; }

/// <summary>
/// The current logical sequence number.
/// </summary>
[JsonProperty(PropertyName = "lsn", NullValueHandling = NullValueHandling.Ignore)]
public long Lsn { get; internal set; }
[JsonPropertyName("lsn")]
public long Lsn { get; }

/// <summary>
/// The change feed operation type.
/// </summary>
[JsonProperty(PropertyName = "operationType")]
[JsonConverter(typeof(StringEnumConverter))]
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved
public ChangeFeedOperationType OperationType { get; internal set; }
[JsonProperty(PropertyName = "operationType", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("operationType")]
public ChangeFeedOperationType OperationType { get; }

/// <summary>
/// The previous logical sequence number.
/// </summary>
[JsonProperty(PropertyName = "previousImageLSN", NullValueHandling = NullValueHandling.Ignore)]
public long PreviousLsn { get; internal set; }
[Newtonsoft.Json.JsonProperty(PropertyName = "previousImageLSN", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("previousImageLSN")]
public long PreviousLSN { get; }
philipthomas-MSFT marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Used to distinquish explicit deletes (e.g. via DeleteItem) from deletes caused by TTL expiration (a collection may define time-to-live policy for documents).
/// </summary>
[JsonProperty(PropertyName = "timeToLiveExpired", NullValueHandling= NullValueHandling.Ignore)]
public bool IsTimeToLiveExpired { get; internal set; }
[JsonProperty(PropertyName = "timeToLiveExpired", NullValueHandling = NullValueHandling.Ignore)]
[JsonPropertyName("timeToLiveExpired")]
public bool IsTimeToLiveExpired { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Resource.FullFidelity.Converters
{
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

/// <summary>
/// UnixDateTimeConverter for System.Text.Json
/// </summary>
internal class STJUnixDateTimeConverter : JsonConverter<DateTime>
{
/// <summary>
/// Read.
/// </summary>
/// <param name="reader"></param>
/// <param name="typeToConvert"></param>
/// <param name="options"></param>
/// <returns>DateTime.</returns>
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.Number)
{
throw new JsonException("Expected a number representing the Unix timestamp.");
}

long unixTime = reader.GetInt64();
return DateTimeOffset.FromUnixTimeSeconds(unixTime).UtcDateTime;
}

/// <summary>
/// Write.
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="options"></param>
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
long unixTime = ((DateTimeOffset)value).ToUnixTimeSeconds();
writer.WriteNumberValue(unixTime);
}
}
}
Loading