Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/api/Azure.Core.net461.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/api/Azure.Core.net5.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/api/Azure.Core.net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/api/Azure.Core.netcoreapp2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/core/Azure.Core/api/Azure.Core.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions sdk/core/Azure.Core/src/SerializableOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
namespace Azure
{
/// <summary>
/// TODO
/// Provides the client options for serializing models.
/// </summary>
public class SerializableOptions
{
/// <summary>
/// TODO
/// Bool that determines if ReadOnlyProperties will be serialized. Default is false.
/// </summary>
public bool IncludeReadOnlyProperties { get; set; } = true;
public bool IgnoreReadOnlyProperties { get; set; }

/// <summary>
/// TODO
/// Bool that determines if AdditionalProperties will be serialized. Default is false.
/// </summary>
public bool HandleAdditionalProperties { get; set; } = true;
public bool IgnoreAdditionalProperties { get; set; }

/// <summary>
/// TODO
/// Bool that determines if Json will be PrettyPrinted. Default is false.
/// </summary>
public bool PrettyPrint { get; set; } = false;
public bool PrettyPrint { get; set; }
}
}
6 changes: 3 additions & 3 deletions sdk/core/Azure.Core/tests/ModelSerializationTests/Animal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -106,7 +106,6 @@ public void PrettyPrint()

var expectedJson = """
{
"latinName": "Animalia",
"name": "Doggo",
"isHungry": false,
"weight": 1.1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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);
Expand Down Expand Up @@ -102,7 +102,6 @@ public void PrettyPrint()

var expectedJson = """
{
"latinName": "Felis catus",
"name": "Catto",
"isHungry": true,
"weight": 3.2,
Expand Down