From e98bbcb0e7857bb262172343d5174b81203af246 Mon Sep 17 00:00:00 2001 From: Nisha Bhatia <67986960+nisha-bhatia@users.noreply.github.com> Date: Tue, 2 May 2023 15:20:43 -0700 Subject: [PATCH 1/4] update api --- sdk/core/Azure.Core/api/Azure.Core.net461.cs | 4 ++-- sdk/core/Azure.Core/api/Azure.Core.net5.0.cs | 4 ++-- sdk/core/Azure.Core/api/Azure.Core.net6.0.cs | 4 ++-- sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs | 4 ++-- sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs | 4 ++-- sdk/core/Azure.Core/src/SerializableOptions.cs | 6 +++--- sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs | 6 +++--- .../tests/ModelSerializationTests/CatReadOnlyProperty.cs | 6 +++--- .../tests/ModelSerializationTests/DogListProperty.cs | 6 +++--- .../tests/ModelSerializationTests/ListPropertyTests.cs | 4 ++-- .../tests/ModelSerializationTests/ReadOnlyPropertyTests.cs | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/sdk/core/Azure.Core/api/Azure.Core.net461.cs b/sdk/core/Azure.Core/api/Azure.Core.net461.cs index a3218d50be79..31a30fc73652 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net461.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net461.cs @@ -270,8 +270,8 @@ protected Response() { } public partial class SerializableOptions { public SerializableOptions() { } - public bool HandleAdditionalProperties { get { throw null; } set { } } - public bool IncludeReadOnlyProperties { get { throw null; } set { } } + public bool IgnoreAdditionalProperties { get { throw null; } set { } } + public bool IgnoreReadOnlyProperties { get { throw null; } set { } } public bool PrettyPrint { get { throw null; } set { } } } public partial class SyncAsyncEventArgs : System.EventArgs diff --git a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs index d135442d4127..740b36f28cb1 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net5.0.cs @@ -270,8 +270,8 @@ protected Response() { } public partial class SerializableOptions { public SerializableOptions() { } - public bool HandleAdditionalProperties { get { throw null; } set { } } - public bool IncludeReadOnlyProperties { get { throw null; } set { } } + public bool IgnoreAdditionalProperties { get { throw null; } set { } } + public bool IgnoreReadOnlyProperties { get { throw null; } set { } } public bool PrettyPrint { get { throw null; } set { } } } public partial class SyncAsyncEventArgs : System.EventArgs diff --git a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs index d135442d4127..740b36f28cb1 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.net6.0.cs @@ -270,8 +270,8 @@ protected Response() { } public partial class SerializableOptions { public SerializableOptions() { } - public bool HandleAdditionalProperties { get { throw null; } set { } } - public bool IncludeReadOnlyProperties { get { throw null; } set { } } + public bool IgnoreAdditionalProperties { get { throw null; } set { } } + public bool IgnoreReadOnlyProperties { get { throw null; } set { } } public bool PrettyPrint { get { throw null; } set { } } } public partial class SyncAsyncEventArgs : System.EventArgs diff --git a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs index a3218d50be79..31a30fc73652 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs @@ -270,8 +270,8 @@ protected Response() { } public partial class SerializableOptions { public SerializableOptions() { } - public bool HandleAdditionalProperties { get { throw null; } set { } } - public bool IncludeReadOnlyProperties { get { throw null; } set { } } + public bool IgnoreAdditionalProperties { get { throw null; } set { } } + public bool IgnoreReadOnlyProperties { get { throw null; } set { } } public bool PrettyPrint { get { throw null; } set { } } } public partial class SyncAsyncEventArgs : System.EventArgs diff --git a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs index a3218d50be79..31a30fc73652 100644 --- a/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs +++ b/sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs @@ -270,8 +270,8 @@ protected Response() { } public partial class SerializableOptions { public SerializableOptions() { } - public bool HandleAdditionalProperties { get { throw null; } set { } } - public bool IncludeReadOnlyProperties { get { throw null; } set { } } + public bool IgnoreAdditionalProperties { get { throw null; } set { } } + public bool IgnoreReadOnlyProperties { get { throw null; } set { } } public bool PrettyPrint { get { throw null; } set { } } } public partial class SyncAsyncEventArgs : System.EventArgs diff --git a/sdk/core/Azure.Core/src/SerializableOptions.cs b/sdk/core/Azure.Core/src/SerializableOptions.cs index 61f2419d7843..ee0c13de723f 100644 --- a/sdk/core/Azure.Core/src/SerializableOptions.cs +++ b/sdk/core/Azure.Core/src/SerializableOptions.cs @@ -4,19 +4,19 @@ namespace Azure { /// - /// TODO + /// Provides the client options for serializing models. /// public class SerializableOptions { /// /// TODO /// - public bool IncludeReadOnlyProperties { get; set; } = true; + public bool IgnoreReadOnlyProperties { get; set; } = false; /// /// TODO /// - public bool HandleAdditionalProperties { get; set; } = true; + public bool IgnoreAdditionalProperties { get; set; } = false; /// /// TODO diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs index 907e2918fe1d..187d3073a486 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs @@ -47,7 +47,7 @@ internal Animal(string name) void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions options) { writer.WriteStartObject(); - if (options.IncludeReadOnlyProperties) + if (options.IgnoreReadOnlyProperties) { writer.WritePropertyName("latinName"u8); writer.WriteStringValue(LatinName); @@ -59,7 +59,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions opti writer.WritePropertyName("weight"u8); writer.WriteNumberValue(Weight); - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //write out the raw data foreach (var property in RawData) @@ -106,7 +106,7 @@ internal static Animal DeserializeAnimal(JsonElement element, SerializableOption continue; } - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //this means it's an unknown property we got rawData.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/CatReadOnlyProperty.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/CatReadOnlyProperty.cs index 4f7152db6921..c8431b5b56ea 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/CatReadOnlyProperty.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/CatReadOnlyProperty.cs @@ -28,7 +28,7 @@ internal CatReadOnlyProperty(double weight, string latinName, string name, bool void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions options) { writer.WriteStartObject(); - if (options.IncludeReadOnlyProperties) + if (options.IgnoreReadOnlyProperties) { writer.WritePropertyName("latinName"u8); writer.WriteStringValue(LatinName); @@ -42,7 +42,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions opti writer.WritePropertyName("hasWhiskers"u8); writer.WriteBooleanValue(HasWhiskers); - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //write out the raw data foreach (var property in RawData) @@ -95,7 +95,7 @@ internal static CatReadOnlyProperty DeserializeCatReadOnlyProperty(JsonElement e continue; } - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //this means its an unknown property we got rawData.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/DogListProperty.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/DogListProperty.cs index 6dfae6392b9b..bd5bed7f0ba4 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/DogListProperty.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/DogListProperty.cs @@ -32,7 +32,7 @@ public DogListProperty() void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions options) { writer.WriteStartObject(); - if (options.IncludeReadOnlyProperties) + if (options.IgnoreReadOnlyProperties) { writer.WritePropertyName("latinName"u8); writer.WriteStringValue(LatinName); @@ -52,7 +52,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer, SerializableOptions opti } writer.WriteEndArray(); - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //write out the raw data foreach (var property in RawData) @@ -107,7 +107,7 @@ internal static DogListProperty DeserializeDogListProperty(JsonElement element, } continue; } - if (options.HandleAdditionalProperties) + if (options.IgnoreAdditionalProperties) { //this means its an unknown property we got rawData.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs index 9b17adad84b0..b989cb093dbb 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs @@ -14,7 +14,7 @@ namespace Azure.Core.Tests.ModelSerializationTests { public class ListPropertyTests { - private readonly SerializableOptions _wireOptions = new SerializableOptions { IncludeReadOnlyProperties = false }; + private readonly SerializableOptions _wireOptions = new SerializableOptions { IgnoreReadOnlyProperties = false }; private readonly SerializableOptions _objectOptions = new SerializableOptions(); [TestCase(true, true)] @@ -43,7 +43,7 @@ public void CanRoundTripFutureVersionWithoutLoss(bool includeReadonly, bool hand expectedSerialized.Append("}"); var expectedSerializedString = expectedSerialized.ToString(); - SerializableOptions options = new SerializableOptions() { IncludeReadOnlyProperties = includeReadonly, HandleAdditionalProperties = handleUnknown }; + SerializableOptions options = new SerializableOptions() { IgnoreReadOnlyProperties = includeReadonly, IgnoreAdditionalProperties = handleUnknown }; var model = new DogListProperty(); model.TryDeserialize(new MemoryStream(Encoding.UTF8.GetBytes(serviceResponse)), out long bytesConsumed, options: options); diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs index 5aba9069c5cb..c5012d7e6455 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs @@ -14,7 +14,7 @@ namespace Azure.Core.Tests.ModelSerializationTests { public class ReadOnlyPropertyTests { - private readonly SerializableOptions _wireOptions = new SerializableOptions { IncludeReadOnlyProperties = false }; + private readonly SerializableOptions _wireOptions = new SerializableOptions { IgnoreReadOnlyProperties = false }; private readonly SerializableOptions _objectOptions = new SerializableOptions(); [TestCase(true, true)] @@ -41,7 +41,7 @@ public void CanRoundTripFutureVersionWithoutLoss(bool includeReadonly, bool hand expectedSerialized.Append("}"); var expectedSerializedString = expectedSerialized.ToString(); - SerializableOptions options = new SerializableOptions() { IncludeReadOnlyProperties = includeReadonly, HandleAdditionalProperties = handleUnknown }; + SerializableOptions options = new SerializableOptions() { IgnoreReadOnlyProperties = includeReadonly, IgnoreAdditionalProperties = handleUnknown }; var model = new Animal(); model.TryDeserialize(new MemoryStream(Encoding.UTF8.GetBytes(serviceResponse)), out long bytesConsumed, options: options); From 32076a8a1f070f6950f6887e5c4046598c711c9e Mon Sep 17 00:00:00 2001 From: Nisha Bhatia <67986960+nisha-bhatia@users.noreply.github.com> Date: Tue, 2 May 2023 15:38:05 -0700 Subject: [PATCH 2/4] Update SerializableOptions.cs --- sdk/core/Azure.Core/src/SerializableOptions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdk/core/Azure.Core/src/SerializableOptions.cs b/sdk/core/Azure.Core/src/SerializableOptions.cs index ee0c13de723f..cd00da019dca 100644 --- a/sdk/core/Azure.Core/src/SerializableOptions.cs +++ b/sdk/core/Azure.Core/src/SerializableOptions.cs @@ -9,18 +9,18 @@ namespace Azure public class SerializableOptions { /// - /// TODO + /// Bool that determines if ReadOnlyProperties will be serialized. Default is false. /// - public bool IgnoreReadOnlyProperties { get; set; } = false; + public bool IgnoreReadOnlyProperties { get; set; } /// - /// TODO + /// Bool that determines if AdditionalProperties will be serialized. Default is false. /// - public bool IgnoreAdditionalProperties { get; set; } = false; + public bool IgnoreAdditionalProperties { get; set; } /// - /// TODO + /// Bool that determines if Json will be PrettyPrinted. Default is false. /// - public bool PrettyPrint { get; set; } = false; + public bool PrettyPrint { get; set; } } } From 3b75453ca946201271096e2c3655e2309ded56bd Mon Sep 17 00:00:00 2001 From: Nisha Bhatia <67986960+nisha-bhatia@users.noreply.github.com> Date: Tue, 2 May 2023 16:20:17 -0700 Subject: [PATCH 3/4] wip --- .../ModelSerializationTests/ListPropertyTests.cs | 14 +------------- .../ReadOnlyPropertyTests.cs | 10 +--------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs index b989cb093dbb..292d2ae6b997 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs @@ -104,19 +104,7 @@ public void PrettyPrint() stream.Position = 0; var actualJson = new StreamReader(stream).ReadToEnd(); - var expectedJson = """ - { - "latinName": "Animalia", - "name": "Doggo", - "isHungry": false, - "weight": 1.1, - "foodConsumed": [ - "kibble", - "egg", - "peanut butter" - ] - } - """; + var expectedJson = "{\r\n \"name\": \"Doggo\",\r\n \"isHungry\": false,\r\n \"weight\": 1.1,\r\n \"foodConsumed\": [\r\n \"kibble\",\r\n \"egg\",\r\n \"peanut butter\"\r\n ]\r\n}"; Assert.AreEqual(expectedJson, actualJson); } diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs index c5012d7e6455..ee2dfb226da9 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs @@ -100,15 +100,7 @@ public void PrettyPrint() stream.Position = 0; var actualJson = new StreamReader(stream).ReadToEnd(); - var expectedJson = """ - { - "latinName": "Felis catus", - "name": "Catto", - "isHungry": true, - "weight": 3.2, - "hasWhiskers": false - } - """; + var expectedJson = "{\r\n \"name\": \"Catto\",\r\n \"isHungry\": true,\r\n \"weight\": 3.2,\r\n \"hasWhiskers\": false\r\n}"; Assert.AreEqual(expectedJson, actualJson); } From 6b605274c28a741e4e0b69b7bbce8125864175e9 Mon Sep 17 00:00:00 2001 From: Nisha Bhatia <67986960+nisha-bhatia@users.noreply.github.com> Date: Wed, 3 May 2023 12:08:31 -0700 Subject: [PATCH 4/4] prettyprint --- .../ModelSerializationTests/ListPropertyTests.cs | 13 ++++++++++++- .../ReadOnlyPropertyTests.cs | 9 ++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs index 292d2ae6b997..864dc0e8f38a 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ListPropertyTests.cs @@ -104,7 +104,18 @@ public void PrettyPrint() stream.Position = 0; var actualJson = new StreamReader(stream).ReadToEnd(); - var expectedJson = "{\r\n \"name\": \"Doggo\",\r\n \"isHungry\": false,\r\n \"weight\": 1.1,\r\n \"foodConsumed\": [\r\n \"kibble\",\r\n \"egg\",\r\n \"peanut butter\"\r\n ]\r\n}"; + var expectedJson = """ + { + "name": "Doggo", + "isHungry": false, + "weight": 1.1, + "foodConsumed": [ + "kibble", + "egg", + "peanut butter" + ] + } + """; Assert.AreEqual(expectedJson, actualJson); } diff --git a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs index ee2dfb226da9..16e297226161 100644 --- a/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerializationTests/ReadOnlyPropertyTests.cs @@ -100,7 +100,14 @@ public void PrettyPrint() stream.Position = 0; var actualJson = new StreamReader(stream).ReadToEnd(); - var expectedJson = "{\r\n \"name\": \"Catto\",\r\n \"isHungry\": true,\r\n \"weight\": 3.2,\r\n \"hasWhiskers\": false\r\n}"; + var expectedJson = """ + { + "name": "Catto", + "isHungry": true, + "weight": 3.2, + "hasWhiskers": false + } + """; Assert.AreEqual(expectedJson, actualJson); }