Skip to content

Conversation

@philipthomas-MSFT
Copy link
Contributor

@philipthomas-MSFT philipthomas-MSFT commented Aug 1, 2024

Pull Request Template

Description

Details in #4616

Usage

Deserialize

Payload
string json = @"[
    {
        ""current"": {
            ""id"": ""1"",
            ""pk"": ""1"",
            ""description"": ""original test"",
            ""_rid"": ""HpxDAL+dzLQBAAAAAAAAAA=="",
            ""_self"": ""dbs/HpxDAA==/colls/HpxDAL+dzLQ=/docs/HpxDAL+dzLQBAAAAAAAAAA==/"",
            ""_etag"": ""\""00000000-0000-0000-e384-28095c1a01da\"""",
            ""_attachments"": ""attachments/"",
            ""_ts"": 1722455970
        },
        ""metadata"": {
            ""crts"": 1722455970,
            ""lsn"": 374,
            ""operationType"": ""create"",
            ""previousImageLSN"": 0,
            ""timeToLiveExpired"": false
        }
    },
    {
        ""current"": {
            ""id"": ""1"",
            ""pk"": ""1"",
            ""description"": ""test after replace"",
            ""_rid"": ""HpxDAL+dzLQBAAAAAAAAAA=="",
            ""_self"": ""dbs/HpxDAA==/colls/HpxDAL+dzLQ=/docs/HpxDAL+dzLQBAAAAAAAAAA==/"",
            ""_etag"": ""\""00000000-0000-0000-e384-28a5abdd01da\"""",
            ""_attachments"": ""attachments/"",
            ""_ts"": 1722455971
        },
        ""metadata"": {
            ""crts"": 1722455971,
            ""lsn"": 375,
            ""operationType"": ""replace"",
            ""previousImageLSN"": 374,
            ""timeToLiveExpired"": false
        }
    },
    {
        ""current"": {},
        ""metadata"": {
            ""crts"": 1722455972,
            ""lsn"": 376,
            ""operationType"": ""delete"",
            ""previousImageLSN"": 375,
            ""timeToLiveExpired"": false
        },
        ""previous"": {
            ""id"": ""1"",
            ""pk"": ""1"",
            ""description"": ""test after replace"",
            ""_rid"": ""HpxDAL+dzLQBAAAAAAAAAA=="",
            ""_self"": ""dbs/HpxDAA==/colls/HpxDAL+dzLQ=/docs/HpxDAL+dzLQBAAAAAAAAAA==/"",
            ""_etag"": ""\""00000000-0000-0000-e384-28a5abdd01da\"""",
            ""_attachments"": ""attachments/"",
            ""_ts"": 1722455971
        }
    }
]";
STJ
System.Text.Json.JsonSerializer.Deserialize<List<ChangeFeedItem<ToDoActivity>>>(
	json: json,
	options: new JsonSerializerOptions()
	{
		PropertyNameCaseInsensitive = true,
	});

Serialize

STJ
ChangeFeedMetadata metadata = new()
{
    PreviousLsn = 15,
    Lsn = 374,
    OperationType = ChangeFeedOperationType.Create,
    IsTimeToLiveExpired = true,
    ConflictResolutionTimestamp = DateTime.Parse("7/31/2024 7:59:30 PM")
};

string json = System.Text.Json.JsonSerializer.Serialize<ChangeFeedMetadata>(
    value: metadata,
    options: new JsonSerializerOptions());

With CosmosClientBuilder

CosmosClient cosmosClient = TestCommon.CreateCosmosClient((cosmosClientBuilder) =>
cosmosClientBuilder.WithSystemTextJsonSerializerOptions(
	new JsonSerializerOptions()
	{
		PropertyNameCaseInsensitive = true,
	}),
	useCustomSeralizer: false);

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #4616

…erialization-with-cosmossystemtextjsonserializer-and-custom-serializers
@philipthomas-MSFT philipthomas-MSFT changed the title ChangeFeed/Processor: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json ChangeFeed/Processor AVAD: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json Aug 1, 2024
@philipthomas-MSFT philipthomas-MSFT changed the title ChangeFeed/Processor AVAD: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json CF/P AVAD: Fixes Deserialization of ChangeFeedItem and ChangeFeedMetadata to support System.Text.Json and Newtonsoft.Json Aug 1, 2024
…s-with-serializationdeserialization-with-cosmossystemtextjsonserializer-and-custom-serializers
…s-with-serializationdeserialization-with-cosmossystemtextjsonserializer-and-custom-serializers
…with-cosmossystemtextjsonserializer-and-custom-serializers' of https://github.com/Azure/azure-cosmos-dotnet-v3 into 4616-cfp-avad-issues-with-serializationdeserialization-with-cosmossystemtextjsonserializer-and-custom-serializers
Copy link
Contributor

@NaluTripician NaluTripician left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

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

LGTM

@microsoft-github-policy-service microsoft-github-policy-service bot merged commit a1144f4 into master Aug 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the 4616-cfp-avad-issues-with-serializationdeserialization-with-cosmossystemtextjsonserializer-and-custom-serializers branch August 21, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-merge Enables automation to merge PRs

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

CF/P AVAD: Issues with Serialization/Deserialization with JsonSerializerOptions on Custom serializer and UseSystemTextJsonSerializerWithOptions.

6 participants