diff --git a/Microsoft.Kiota.Abstractions.Tests/Serialization/DeserializationHelpersTests.cs b/Microsoft.Kiota.Abstractions.Tests/Serialization/DeserializationHelpersTests.cs index 7cb78fb6..272d1f4a 100644 --- a/Microsoft.Kiota.Abstractions.Tests/Serialization/DeserializationHelpersTests.cs +++ b/Microsoft.Kiota.Abstractions.Tests/Serialization/DeserializationHelpersTests.cs @@ -14,20 +14,20 @@ public class DeserializationHelpersTests [Fact] public void DefensiveObject() { - Assert.Throws(() => DeserializationHelpers.Deserialize(null, (Stream)null, null)); - Assert.Throws(() => DeserializationHelpers.Deserialize(_jsonContentType, (Stream)null, null)); + Assert.Throws(() => KiotaSerializer.Deserialize(null, (Stream)null, null)); + Assert.Throws(() => KiotaSerializer.Deserialize(_jsonContentType, (Stream)null, null)); using var stream = new MemoryStream(); - Assert.Throws(() => DeserializationHelpers.Deserialize(_jsonContentType, stream, null)); - Assert.Throws(() => DeserializationHelpers.Deserialize(_jsonContentType, "", null)); + Assert.Throws(() => KiotaSerializer.Deserialize(_jsonContentType, stream, null)); + Assert.Throws(() => KiotaSerializer.Deserialize(_jsonContentType, "", null)); } [Fact] public void DefensiveObjectCollection() { - Assert.Throws(() => DeserializationHelpers.DeserializeCollection(null, (Stream)null, null)); - Assert.Throws(() => DeserializationHelpers.DeserializeCollection(_jsonContentType, (Stream)null, null)); + Assert.Throws(() => KiotaSerializer.DeserializeCollection(null, (Stream)null, null)); + Assert.Throws(() => KiotaSerializer.DeserializeCollection(_jsonContentType, (Stream)null, null)); using var stream = new MemoryStream(); - Assert.Throws(() => DeserializationHelpers.DeserializeCollection(_jsonContentType, stream, null)); - Assert.Throws(() => DeserializationHelpers.DeserializeCollection(_jsonContentType, "", null)); + Assert.Throws(() => KiotaSerializer.DeserializeCollection(_jsonContentType, stream, null)); + Assert.Throws(() => KiotaSerializer.DeserializeCollection(_jsonContentType, "", null)); } [Fact] public void DeserializesObjectWithoutReflection() @@ -43,7 +43,7 @@ public void DeserializesObjectWithoutReflection() mockJsonParseNodeFactory.Setup(x => x.ValidContentType).Returns(_jsonContentType); ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories[_jsonContentType] = mockJsonParseNodeFactory.Object; - var result = DeserializationHelpers.Deserialize(_jsonContentType, strValue, TestEntity.CreateFromDiscriminatorValue); + var result = KiotaSerializer.Deserialize(_jsonContentType, strValue, TestEntity.CreateFromDiscriminatorValue); Assert.NotNull(result); } @@ -61,7 +61,7 @@ public void DeserializesObjectWithReflection() mockJsonParseNodeFactory.Setup(x => x.ValidContentType).Returns(_jsonContentType); ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories[_jsonContentType] = mockJsonParseNodeFactory.Object; - var result = DeserializationHelpers.Deserialize(_jsonContentType, strValue); + var result = KiotaSerializer.Deserialize(_jsonContentType, strValue); Assert.NotNull(result); } @@ -81,7 +81,7 @@ public void DeserializesCollectionOfObject() mockJsonParseNodeFactory.Setup(x => x.ValidContentType).Returns(_jsonContentType); ParseNodeFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories[_jsonContentType] = mockJsonParseNodeFactory.Object; - var result = DeserializationHelpers.DeserializeCollection(_jsonContentType, strValue, TestEntity.CreateFromDiscriminatorValue); + var result = KiotaSerializer.DeserializeCollection(_jsonContentType, strValue, TestEntity.CreateFromDiscriminatorValue); Assert.NotNull(result); Assert.Single(result); diff --git a/Microsoft.Kiota.Abstractions.Tests/Serialization/SerializationHelpersTests.cs b/Microsoft.Kiota.Abstractions.Tests/Serialization/SerializationHelpersTests.cs index 4d72605e..79d8e2a9 100644 --- a/Microsoft.Kiota.Abstractions.Tests/Serialization/SerializationHelpersTests.cs +++ b/Microsoft.Kiota.Abstractions.Tests/Serialization/SerializationHelpersTests.cs @@ -15,14 +15,14 @@ public class SerializationHelpersTests [Fact] public void DefensiveObject() { - Assert.Throws(() => SerializationHelpers.SerializeAsStream(null, (TestEntity)null)); - Assert.Throws(() => SerializationHelpers.SerializeAsStream(_jsonContentType, (TestEntity)null)); + Assert.Throws(() => KiotaSerializer.SerializeAsStream(null, (TestEntity)null)); + Assert.Throws(() => KiotaSerializer.SerializeAsStream(_jsonContentType, (TestEntity)null)); } [Fact] public void DefensiveObjectCollection() { - Assert.Throws(() => SerializationHelpers.SerializeAsStream(null, (IEnumerable)null)); - Assert.Throws(() => SerializationHelpers.SerializeAsStream(_jsonContentType, (IEnumerable)null)); + Assert.Throws(() => KiotaSerializer.SerializeAsStream(null, (IEnumerable)null)); + Assert.Throws(() => KiotaSerializer.SerializeAsStream(_jsonContentType, (IEnumerable)null)); } [Fact] public void SerializesObject() @@ -33,7 +33,7 @@ public void SerializesObject() mockSerializationWriterFactory.Setup(x => x.GetSerializationWriter(It.IsAny())).Returns(mockSerializationWriter.Object); SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories[_jsonContentType] = mockSerializationWriterFactory.Object; - var result = SerializationHelpers.SerializeAsString(_jsonContentType, new TestEntity() + var result = KiotaSerializer.SerializeAsString(_jsonContentType, new TestEntity() { Id = "123" }); @@ -53,7 +53,7 @@ public void SerializesObjectCollection() mockSerializationWriterFactory.Setup(x => x.GetSerializationWriter(It.IsAny())).Returns(mockSerializationWriter.Object); SerializationWriterFactoryRegistry.DefaultInstance.ContentTypeAssociatedFactories[_jsonContentType] = mockSerializationWriterFactory.Object; - var result = SerializationHelpers.SerializeAsString(_jsonContentType, new List { + var result = KiotaSerializer.SerializeAsString(_jsonContentType, new List { new() { Id = "123" diff --git a/src/serialization/JsonDeserializationHelpers.cs b/src/serialization/KiotaJsonSerializer.Deserialization.cs similarity index 84% rename from src/serialization/JsonDeserializationHelpers.cs rename to src/serialization/KiotaJsonSerializer.Deserialization.cs index 958b699c..27ac6817 100644 --- a/src/serialization/JsonDeserializationHelpers.cs +++ b/src/serialization/KiotaJsonSerializer.Deserialization.cs @@ -13,7 +13,7 @@ namespace Microsoft.Kiota.Abstractions.Serialization; /// /// Set of helper methods for JSON serialization /// -public static class JsonDeserializationHelpers +public static partial class KiotaJsonSerializer { private const string _jsonContentType = "application/json"; /// @@ -22,14 +22,14 @@ public static class JsonDeserializationHelpers /// The factory to create the object. /// The serialized representation of the object. public static T? Deserialize(string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable - => DeserializationHelpers.Deserialize(_jsonContentType, serializedRepresentation, parsableFactory); + => KiotaSerializer.Deserialize(_jsonContentType, serializedRepresentation, parsableFactory); /// /// Deserializes the given stream into an object. /// /// The stream to deserialize. /// The factory to create the object. public static T? Deserialize(Stream stream, ParsableFactory parsableFactory) where T : IParsable - => DeserializationHelpers.Deserialize(_jsonContentType, stream, parsableFactory); + => KiotaSerializer.Deserialize(_jsonContentType, stream, parsableFactory); /// /// Deserializes the given stream into an object. /// @@ -39,7 +39,7 @@ public static class JsonDeserializationHelpers #else public static T? Deserialize(Stream stream) where T : IParsable #endif - => DeserializationHelpers.Deserialize(_jsonContentType, stream); + => KiotaSerializer.Deserialize(_jsonContentType, stream); /// /// Deserializes the given stream into an object. /// @@ -49,21 +49,21 @@ public static class JsonDeserializationHelpers #else public static T? Deserialize(string serializedRepresentation) where T : IParsable #endif - => DeserializationHelpers.Deserialize(_jsonContentType, serializedRepresentation); + => KiotaSerializer.Deserialize(_jsonContentType, serializedRepresentation); /// /// Deserializes the given stream into a collection of objects based on the content type. /// /// The stream to deserialize. /// The factory to create the object. public static IEnumerable DeserializeCollection(Stream stream, ParsableFactory parsableFactory) where T : IParsable - => DeserializationHelpers.DeserializeCollection(_jsonContentType, stream, parsableFactory); + => KiotaSerializer.DeserializeCollection(_jsonContentType, stream, parsableFactory); /// /// Deserializes the given stream into a collection of objects based on the content type. /// /// The serialized representation of the objects. /// The factory to create the object. public static IEnumerable DeserializeCollection(string serializedRepresentation, ParsableFactory parsableFactory) where T : IParsable - => DeserializationHelpers.DeserializeCollection(_jsonContentType, serializedRepresentation, parsableFactory); + => KiotaSerializer.DeserializeCollection(_jsonContentType, serializedRepresentation, parsableFactory); /// /// Deserializes the given stream into a collection of objects based on the content type. /// @@ -73,7 +73,7 @@ public static IEnumerable DeserializeCollection(string serializedRepresent #else public static IEnumerable DeserializeCollection(Stream stream) where T : IParsable #endif - => DeserializationHelpers.DeserializeCollection(_jsonContentType, stream); + => KiotaSerializer.DeserializeCollection(_jsonContentType, stream); /// /// Deserializes the given stream into a collection of objects based on the content type. /// @@ -83,5 +83,5 @@ public static IEnumerable DeserializeCollection(Stream stream) where T : I #else public static IEnumerable DeserializeCollection(string serializedRepresentation) where T : IParsable #endif - => DeserializationHelpers.DeserializeCollection(_jsonContentType, serializedRepresentation); + => KiotaSerializer.DeserializeCollection(_jsonContentType, serializedRepresentation); } \ No newline at end of file diff --git a/src/serialization/JsonSerializationHelpers.cs b/src/serialization/KiotaJsonSerializer.Serialization.cs similarity index 81% rename from src/serialization/JsonSerializationHelpers.cs rename to src/serialization/KiotaJsonSerializer.Serialization.cs index 96c7913c..aa87f420 100644 --- a/src/serialization/JsonSerializationHelpers.cs +++ b/src/serialization/KiotaJsonSerializer.Serialization.cs @@ -10,12 +10,8 @@ namespace Microsoft.Kiota.Abstractions.Serialization; -/// -/// Set of helper methods for JSON serialization -/// -public static class JsonSerializationHelpers +public static partial class KiotaJsonSerializer { - private const string _jsonContentType = "application/json"; /// /// Serializes the given object into a string based on the content type. /// @@ -23,7 +19,7 @@ public static class JsonSerializationHelpers /// The object to serialize. /// The serialized representation as a stream. public static Stream SerializeAsStream(T value) where T : IParsable - => SerializationHelpers.SerializeAsStream(_jsonContentType, value); + => KiotaSerializer.SerializeAsStream(_jsonContentType, value); /// /// Serializes the given object into a string based on the content type. @@ -32,7 +28,7 @@ public static Stream SerializeAsStream(T value) where T : IParsable /// The object to serialize. /// The serialized representation as a string. public static string SerializeAsString(T value) where T : IParsable - => SerializationHelpers.SerializeAsString(_jsonContentType, value); + => KiotaSerializer.SerializeAsString(_jsonContentType, value); /// /// Serializes the given object into a string based on the content type. @@ -41,7 +37,7 @@ public static string SerializeAsString(T value) where T : IParsable /// The object to serialize. /// The serialized representation as a stream. public static Stream SerializeAsStream(IEnumerable value) where T : IParsable - => SerializationHelpers.SerializeAsStream(_jsonContentType, value); + => KiotaSerializer.SerializeAsStream(_jsonContentType, value); /// /// Serializes the given object into a string based on the content type. @@ -50,6 +46,6 @@ public static Stream SerializeAsStream(IEnumerable value) where T : IParsa /// The object to serialize. /// The serialized representation as a string. public static string SerializeAsString(IEnumerable value) where T : IParsable - => SerializationHelpers.SerializeAsString(_jsonContentType, value); + => KiotaSerializer.SerializeAsString(_jsonContentType, value); } \ No newline at end of file diff --git a/src/serialization/DeserializationHelpers.cs b/src/serialization/KiotaSerializer.Deserialization.cs similarity index 98% rename from src/serialization/DeserializationHelpers.cs rename to src/serialization/KiotaSerializer.Deserialization.cs index 3cd2655d..5756b08c 100644 --- a/src/serialization/DeserializationHelpers.cs +++ b/src/serialization/KiotaSerializer.Deserialization.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; #if NET5_0_OR_GREATER using System.Diagnostics.CodeAnalysis; @@ -14,10 +13,7 @@ namespace Microsoft.Kiota.Abstractions.Serialization; -/// -/// Set of helper methods for serialization -/// -public static class DeserializationHelpers +public static partial class KiotaSerializer { /// /// Deserializes the given stream into an object based on the content type. diff --git a/src/serialization/SerializationHelpers.cs b/src/serialization/KiotaSerializer.Serialization.cs similarity index 98% rename from src/serialization/SerializationHelpers.cs rename to src/serialization/KiotaSerializer.Serialization.cs index 2749ed5d..7abbd99b 100644 --- a/src/serialization/SerializationHelpers.cs +++ b/src/serialization/KiotaSerializer.Serialization.cs @@ -15,7 +15,7 @@ namespace Microsoft.Kiota.Abstractions.Serialization; /// /// Set of helper methods for serialization /// -public static class SerializationHelpers +public static partial class KiotaSerializer { /// /// Serializes the given object into a string based on the content type.