diff --git a/sdk/core/Azure.Core/src/Serialization/IModelJsonSerializable.cs b/sdk/core/Azure.Core/src/Serialization/IModelJsonSerializable.cs index 81a87ce56b00..6659988e6bd3 100644 --- a/sdk/core/Azure.Core/src/Serialization/IModelJsonSerializable.cs +++ b/sdk/core/Azure.Core/src/Serialization/IModelJsonSerializable.cs @@ -17,7 +17,7 @@ public interface IModelJsonSerializable : IModelSerializable /// /// The to serialize into. /// The to use. - /// If the model does not support the requested . + /// If the model does not support the requested . /// If format is passed in and the model does not use JSON for its wire format. #pragma warning disable AZC0014 // Avoid using banned types in public API void Serialize(Utf8JsonWriter writer, ModelSerializerOptions options); @@ -29,7 +29,7 @@ public interface IModelJsonSerializable : IModelSerializable /// The to read. /// The to use. /// A representation of the JSON value. - /// If the model does not support the requested . + /// If the model does not support the requested . /// If format is passed in and the model does not use JSON for its wire format. #pragma warning disable AZC0014 // Avoid using banned types in public API T Deserialize(ref Utf8JsonReader reader, ModelSerializerOptions options); diff --git a/sdk/core/Azure.Core/src/Serialization/IModelSerializable.cs b/sdk/core/Azure.Core/src/Serialization/IModelSerializable.cs index 13723465f02e..91657484a2e0 100644 --- a/sdk/core/Azure.Core/src/Serialization/IModelSerializable.cs +++ b/sdk/core/Azure.Core/src/Serialization/IModelSerializable.cs @@ -17,7 +17,7 @@ public interface IModelSerializable /// /// The to use. /// A binary representation of the serialized model. - /// If the model does not support the requested . + /// If the model does not support the requested . BinaryData Serialize(ModelSerializerOptions options); /// @@ -26,7 +26,7 @@ public interface IModelSerializable /// The to parse. /// The to use. /// A representation of the data. - /// If the model does not support the requested . + /// If the model does not support the requested . T Deserialize(BinaryData data, ModelSerializerOptions options); } } diff --git a/sdk/core/Azure.Core/src/Serialization/ModelSerializer.cs b/sdk/core/Azure.Core/src/Serialization/ModelSerializer.cs index 765b4b5aac98..981522dd264c 100644 --- a/sdk/core/Azure.Core/src/Serialization/ModelSerializer.cs +++ b/sdk/core/Azure.Core/src/Serialization/ModelSerializer.cs @@ -18,7 +18,7 @@ public static class ModelSerializer /// The model to convert. /// The to use. /// A representation of the model in the specified by the . - /// If the model does not support the requested . + /// If the model does not support the requested . public static BinaryData Serialize(T model, ModelSerializerOptions? options = default) where T : IModelSerializable { options ??= ModelSerializerOptions.DefaultWireOptions; @@ -33,7 +33,7 @@ public static BinaryData Serialize(T model, ModelSerializerOptions? options = /// The model to convert. /// The to use. /// A representation of the model in the specified by the . - /// If the model does not support the requested . + /// If the model does not support the requested . public static BinaryData Serialize(T model, ModelSerializerFormat format) where T : IModelSerializable => Serialize(model, ModelSerializerOptions.GetOptions(format)); @@ -45,7 +45,7 @@ public static BinaryData Serialize(T model, ModelSerializerFormat format) /// The to use. /// A representation of the model in the specified by the . /// Throws if does not implement . - /// If the model does not support the requested . + /// If the model does not support the requested . public static BinaryData Serialize(object model, ModelSerializerOptions? options = default) { options ??= ModelSerializerOptions.DefaultWireOptions; @@ -66,7 +66,7 @@ public static BinaryData Serialize(object model, ModelSerializerOptions? options /// The to use. /// A representation of the model in the specified by the . /// Throws if does not implement . - /// If the model does not support the requested . + /// If the model does not support the requested . public static BinaryData Serialize(object model, ModelSerializerFormat format) => Serialize(model, ModelSerializerOptions.GetOptions(format)); @@ -77,7 +77,7 @@ public static BinaryData Serialize(object model, ModelSerializerFormat format) /// The to use. /// A representation of the . /// Throws if does not have a public or internal parameterless constructor. - /// If the model does not support the requested . + /// If the model does not support the requested . public static T Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(BinaryData data, ModelSerializerOptions? options = default) where T : IModelSerializable { options ??= ModelSerializerOptions.DefaultWireOptions; @@ -92,7 +92,7 @@ public static BinaryData Serialize(object model, ModelSerializerFormat format) /// The to use. /// A representation of the . /// Throws if does not have a public or internal parameterless constructor. - /// If the model does not support the requested . + /// If the model does not support the requested . public static T Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(BinaryData data, ModelSerializerFormat format) where T : IModelSerializable => Deserialize(data, ModelSerializerOptions.GetOptions(format)); @@ -106,7 +106,7 @@ public static BinaryData Serialize(object model, ModelSerializerFormat format) /// A representation of the . /// Throws if does not implement . /// Throws if does not have a public or internal parameterless constructor. - /// If the model does not support the requested . + /// If the model does not support the requested . public static object Deserialize(BinaryData data, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type returnType, ModelSerializerOptions? options = default) { options ??= ModelSerializerOptions.DefaultWireOptions; @@ -123,7 +123,7 @@ public static object Deserialize(BinaryData data, [DynamicallyAccessedMembers(Dy /// A representation of the . /// Throws if does not implement . /// Throws if does not have a public or internal parameterless constructor. - /// If the model does not support the requested . + /// If the model does not support the requested . public static object Deserialize(BinaryData data, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type returnType, ModelSerializerFormat format) => Deserialize(data, returnType, ModelSerializerOptions.GetOptions(format)); diff --git a/sdk/core/Azure.Core/src/Shared/ModelSerializerHelper.cs b/sdk/core/Azure.Core/src/Shared/ModelSerializerHelper.cs index 63510bcd2d73..45481db3c91a 100644 --- a/sdk/core/Azure.Core/src/Shared/ModelSerializerHelper.cs +++ b/sdk/core/Azure.Core/src/Shared/ModelSerializerHelper.cs @@ -16,7 +16,7 @@ public static void ValidateFormat(IModelSerializable model, ModelSerialize bool isValid = (format == ModelSerializerFormat.Json && implementsJson) || format == ModelSerializerFormat.Wire; if (!isValid) { - throw new NotSupportedException($"The model {model.GetType().Name} does not support '{format}' format."); + throw new FormatException($"The model {model.GetType().Name} does not support '{format}' format."); } } diff --git a/sdk/core/Azure.Core/tests/ModelSerialization/ModelWriterTests.cs b/sdk/core/Azure.Core/tests/ModelSerialization/ModelWriterTests.cs index 0456af241f5c..960e5e32295c 100644 --- a/sdk/core/Azure.Core/tests/ModelSerialization/ModelWriterTests.cs +++ b/sdk/core/Azure.Core/tests/ModelSerialization/ModelWriterTests.cs @@ -30,7 +30,7 @@ public void ThrowsIfUnsupportedFormat() { ModelXml model = ModelSerializer.Deserialize(BinaryData.FromString(File.ReadAllText(TestData.GetLocation("ModelXml.xml")))); ModelWriter writer = new ModelWriter(model, new ModelSerializerOptions("x")); - Assert.Throws(() => writer.ToBinaryData()); + Assert.Throws(() => writer.ToBinaryData()); } [Test] diff --git a/sdk/core/Azure.Core/tests/public/ModelSerializationTests/ModelTests.cs b/sdk/core/Azure.Core/tests/public/ModelSerializationTests/ModelTests.cs index 82fa01e281a0..8439f2e19529 100644 --- a/sdk/core/Azure.Core/tests/public/ModelSerializationTests/ModelTests.cs +++ b/sdk/core/Azure.Core/tests/public/ModelSerializationTests/ModelTests.cs @@ -122,8 +122,8 @@ private bool AssertFailures(RoundTripStrategy strategy, ModelSerializerFormat } else if (ModelInstance is not IModelJsonSerializable && format == ModelSerializerFormat.Json) { - Assert.Throws(() => { T model = (T)strategy.Deserialize(serviceResponse, ModelInstance, options); }); - Assert.Throws(() => { var data = strategy.Serialize(ModelInstance, options); }); + Assert.Throws(() => { T model = (T)strategy.Deserialize(serviceResponse, ModelInstance, options); }); + Assert.Throws(() => { var data = strategy.Serialize(ModelInstance, options); }); result = true; } return result; @@ -144,22 +144,22 @@ internal static Dictionary GetRawData(object model) public void ThrowsIfUnknownFormat() { ModelSerializerOptions options = new ModelSerializerOptions("x"); - Assert.Throws(() => ModelSerializer.Serialize(ModelInstance, options)); - Assert.Throws(() => ModelSerializer.Deserialize(new BinaryData("x"), options)); + Assert.Throws(() => ModelSerializer.Serialize(ModelInstance, options)); + Assert.Throws(() => ModelSerializer.Deserialize(new BinaryData("x"), options)); - Assert.Throws(() => ModelSerializer.Serialize((IModelSerializable)ModelInstance, options)); - Assert.Throws(() => ModelSerializer.Deserialize(new BinaryData("x"), typeof(T), options)); + Assert.Throws(() => ModelSerializer.Serialize((IModelSerializable)ModelInstance, options)); + Assert.Throws(() => ModelSerializer.Deserialize(new BinaryData("x"), typeof(T), options)); if (ModelInstance is IModelJsonSerializable jsonModel) { - Assert.Throws(() => jsonModel.Serialize(new Utf8JsonWriter(new MemoryStream()), options)); - Assert.Throws(() => ((IModelJsonSerializable)jsonModel).Serialize(new Utf8JsonWriter(new MemoryStream()), options)); + Assert.Throws(() => jsonModel.Serialize(new Utf8JsonWriter(new MemoryStream()), options)); + Assert.Throws(() => ((IModelJsonSerializable)jsonModel).Serialize(new Utf8JsonWriter(new MemoryStream()), options)); bool gotException = false; try { Utf8JsonReader reader = default; jsonModel.Deserialize(ref reader, options); } - catch (NotSupportedException) + catch (FormatException) { gotException = true; } @@ -174,7 +174,7 @@ public void ThrowsIfUnknownFormat() Utf8JsonReader reader = default; ((IModelJsonSerializable)jsonModel).Deserialize(ref reader, options); } - catch (NotSupportedException) + catch (FormatException) { gotException = true; }