Skip to content

Commit

Permalink
Container serialization include PartitionKeyDefinition only if not nu…
Browse files Browse the repository at this point in the history
…ll (#653)

* Do not write partitionKey when the value is null

* add test
  • Loading branch information
jasontho-ms authored and kirankumarkolli committed Aug 8, 2019
1 parent 834d66b commit 50d944c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ internal ContainerProperties(string id, PartitionKeyDefinition partitionKeyDefin
/// <value>
/// <see cref="PartitionKeyDefinition"/> object.
/// </value>
[JsonProperty(PropertyName = Constants.Properties.PartitionKey)]
[JsonProperty(PropertyName = Constants.Properties.PartitionKey, NullValueHandling = NullValueHandling.Ignore)]
internal PartitionKeyDefinition PartitionKey { get; set; } = new PartitionKeyDefinition();

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ public async Task ContainerSettingsIndexTest()
Assert.AreEqual(containerJsonString, containerJsonAfterConversion);
}

[TestMethod]
public void ContainerSettingsNullPartitionKeyTest()
{
ContainerProperties cosmosContainerSettings = new ContainerProperties("id", "/partitionKey")
{
PartitionKey = null
};

string cosmosSerialized = SettingsContractTests.CosmosSerialize(cosmosContainerSettings);
Assert.IsFalse(cosmosSerialized.Contains("partitionKey"));
}

[TestMethod]
public async Task ContainerV2CompatTest()
{
Expand Down

0 comments on commit 50d944c

Please sign in to comment.