Skip to content

Commit

Permalink
Merge pull request #367 from microsoft/fix/required-cancellation-token
Browse files Browse the repository at this point in the history
fix: optional parameters alignments for serialization methods
  • Loading branch information
baywet authored Sep 3, 2024
2 parents b94cd7b + 57d7e18 commit 87fba64
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.12.3] - 2024-09-03

### Changed

- Fixed optional parameters in KiotaJsonSerialization. [#366](https://github.com/microsoft/kiota-dotnet/issues/366)

## [1.12.2] - 2024-08-23

### Changed

- Fixed a bug where calls to ApiClientBuilder.EnableBackingStoreForParseNodeFactory and ApiClientBuilder.EnableBackingStoreForSerializationWriterFactory would enable a BackingStore around BackingStores. [#2563] (https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2563) [#2588] (https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2588)
- Fixed a bug where calls to ApiClientBuilder.EnableBackingStoreForParseNodeFactory and ApiClientBuilder.EnableBackingStoreForSerializationWriterFactory would enable a BackingStore around BackingStores. [#2563] (<https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2563>) [#2588] (<https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2588>)

## [1.12.1] - 2024-08-21

Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- Common default project properties for ALL projects-->
<PropertyGroup>
<VersionPrefix>1.12.2</VersionPrefix>
<VersionPrefix>1.12.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- This is overidden in test projects by setting to true-->
<IsTestProject>false</IsTestProject>
Expand Down
3 changes: 3 additions & 0 deletions src/abstractions/RequestInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization;
using Microsoft.Kiota.Abstractions.Extensions;
using Microsoft.Kiota.Abstractions.Serialization;

#if NET5_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
Expand Down Expand Up @@ -316,6 +318,7 @@ public void SetResponseHandler(IResponseHandler responseHandler)
/// </summary>
/// <param name="content">The binary stream to set as a body.</param>
[Obsolete("Use SetStreamContent and pass the content type instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetStreamContent(Stream content) => SetStreamContent(content, BinaryContentType);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/abstractions/serialization/IParseNodeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.IO;

namespace Microsoft.Kiota.Abstractions.Serialization
Expand All @@ -23,6 +24,7 @@ public interface IParseNodeFactory
/// <param name="contentType">The content type of the parse node.</param>
/// <returns>A parse node.</returns>
[Obsolete("Use GetRootParseNodeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
IParseNode GetRootParseNode(string contentType, Stream content);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

#if NET5_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
Expand All @@ -25,6 +27,7 @@ public static partial class KiotaJsonSerializer
/// <param name="parsableFactory">The factory to create the object.</param>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T? Deserialize<T>(string serializedRepresentation, ParsableFactory<T> parsableFactory) where T : IParsable
=> KiotaSerializer.Deserialize(_jsonContentType, serializedRepresentation, parsableFactory);
/// <summary>
Expand All @@ -33,13 +36,15 @@ public static partial class KiotaJsonSerializer
/// <param name="stream">The stream to deserialize.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T? Deserialize<T>(Stream stream, ParsableFactory<T> parsableFactory) where T : IParsable
=> KiotaSerializer.Deserialize(_jsonContentType, stream, parsableFactory);
/// <summary>
/// Deserializes the given stream into an object.
/// </summary>
/// <param name="stream">The stream to deserialize.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static T? Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(Stream stream) where T : IParsable
#else
Expand All @@ -51,6 +56,7 @@ public static partial class KiotaJsonSerializer
/// </summary>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static T? Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string serializedRepresentation) where T : IParsable
#else
Expand All @@ -63,6 +69,7 @@ public static partial class KiotaJsonSerializer
/// <param name="stream">The stream to deserialize.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<T> DeserializeCollection<T>(Stream stream, ParsableFactory<T> parsableFactory) where T : IParsable
=> KiotaSerializer.DeserializeCollection(_jsonContentType, stream, parsableFactory);
/// <summary>
Expand All @@ -71,13 +78,15 @@ public static IEnumerable<T> DeserializeCollection<T>(Stream stream, ParsableFac
/// <param name="serializedRepresentation">The serialized representation of the objects.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<T> DeserializeCollection<T>(string serializedRepresentation, ParsableFactory<T> parsableFactory) where T : IParsable
=> KiotaSerializer.DeserializeCollection(_jsonContentType, serializedRepresentation, parsableFactory);
/// <summary>
/// Deserializes the given stream into a collection of objects based on the content type.
/// </summary>
/// <param name="stream">The stream to deserialize.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static IEnumerable<T> DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(Stream stream) where T : IParsable
#else
Expand All @@ -89,6 +98,7 @@ public static IEnumerable<T> DeserializeCollection<T>(Stream stream) where T : I
/// </summary>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static IEnumerable<T> DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string serializedRepresentation) where T : IParsable
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public static partial class KiotaJsonSerializer
/// </summary>
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="value">The object to serialize.</param>
/// <param name="serializeOnlyChangedValues">By default, you'll only get the changed properties.</param>
/// <returns>The serialized representation as a stream.</returns>
public static Stream SerializeAsStream<T>(T value) where T : IParsable
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value);
public static Stream SerializeAsStream<T>(T value, bool serializeOnlyChangedValues = true) where T : IParsable

Check warning on line 27 in src/abstractions/serialization/KiotaJsonSerializer.Serialization.cs

View workflow job for this annotation

GitHub Actions / Build

All 'SerializeAsStream' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value, serializeOnlyChangedValues);

/// <summary>
/// Serializes the given object into a string based on the content type.
Expand All @@ -44,17 +45,31 @@ public static string SerializeAsString<T>(T value) where T : IParsable
/// <param name="value">The object to serialize.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use SerializeAsStringAsync with optional CancellationToken parameter instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Task<string> SerializeAsStringAsync<T>(T value, CancellationToken cancellationToken) where T : IParsable

Check warning on line 50 in src/abstractions/serialization/KiotaJsonSerializer.Serialization.cs

View workflow job for this annotation

GitHub Actions / Build

All 'SerializeAsStringAsync' method overloads should be adjacent. (https://rules.sonarsource.com/csharp/RSPEC-4136)
=> KiotaSerializer.SerializeAsStringAsync(_jsonContentType, value, true, cancellationToken);
=> SerializeAsStringAsync(value, true, cancellationToken);

/// <summary>
/// Serializes the given object into a string based on the content type.
/// </summary>
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="value">The object to serialize.</param>
/// <param name="serializeOnlyChangedValues">By default, you'll only get the changed properties.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The serialized representation as a string.</returns>
public static Task<string> SerializeAsStringAsync<T>(T value, bool serializeOnlyChangedValues = true, CancellationToken cancellationToken = default) where T : IParsable
=> KiotaSerializer.SerializeAsStringAsync(_jsonContentType, value, serializeOnlyChangedValues, cancellationToken);

/// <summary>
/// Serializes the given object into a string based on the content type.
/// </summary>
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="value">The object to serialize.</param>
/// <param name="serializeOnlyChangedValues">By default, you'll only get the changed properties.</param>
/// <returns>The serialized representation as a stream.</returns>
public static Stream SerializeAsStream<T>(IEnumerable<T> value) where T : IParsable
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value);
public static Stream SerializeAsStream<T>(IEnumerable<T> value, bool serializeOnlyChangedValues = true) where T : IParsable
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value, serializeOnlyChangedValues);

/// <summary>
/// Serializes the given object into a string based on the content type.
Expand All @@ -73,6 +88,19 @@ public static string SerializeAsString<T>(IEnumerable<T> value) where T : IParsa
/// <param name="value">The object to serialize.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use SerializeAsStringAsync with optional CancellationToken parameter instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Task<string> SerializeAsStringAsync<T>(IEnumerable<T> value, CancellationToken cancellationToken) where T : IParsable =>
KiotaSerializer.SerializeAsStringAsync(_jsonContentType, value, true, cancellationToken);
SerializeAsStringAsync(value, true, cancellationToken);

/// <summary>
/// Serializes the given object into a string based on the content type.
/// </summary>
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="value">The object to serialize.</param>
/// <param name="serializeOnlyChangedValues">By default, you'll only get the changed properties.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The serialized representation as a string.</returns>
public static Task<string> SerializeAsStringAsync<T>(IEnumerable<T> value, bool serializeOnlyChangedValues = true, CancellationToken cancellationToken = default) where T : IParsable =>
KiotaSerializer.SerializeAsStringAsync(_jsonContentType, value, serializeOnlyChangedValues, cancellationToken);
}
10 changes: 10 additions & 0 deletions src/abstractions/serialization/KiotaSerializer.Deserialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

#if NET5_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
Expand All @@ -24,6 +26,7 @@ public static partial class KiotaSerializer
/// <param name="parsableFactory">The factory to create the object.</param>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T? Deserialize<T>(string contentType, string serializedRepresentation, ParsableFactory<T> parsableFactory) where T : IParsable
{
if(string.IsNullOrEmpty(serializedRepresentation)) throw new ArgumentNullException(nameof(serializedRepresentation));
Expand All @@ -49,6 +52,7 @@ private static Stream GetStreamFromString(string source)
/// <param name="stream">The stream to deserialize.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static T? Deserialize<T>(string contentType, Stream stream, ParsableFactory<T> parsableFactory) where T : IParsable
{
if(string.IsNullOrEmpty(contentType)) throw new ArgumentNullException(nameof(contentType));
Expand All @@ -63,6 +67,7 @@ private static Stream GetStreamFromString(string source)
/// <param name="contentType">The content type of the stream.</param>
/// <param name="stream">The stream to deserialize.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static T? Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, Stream stream) where T : IParsable
#else
Expand All @@ -86,6 +91,7 @@ private static ParsableFactory<T> GetFactoryFromType<T>() where T : IParsable
/// <param name="contentType">The content type of the stream.</param>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static T? Deserialize<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, string serializedRepresentation) where T : IParsable
#else
Expand All @@ -100,6 +106,7 @@ private static ParsableFactory<T> GetFactoryFromType<T>() where T : IParsable
/// <param name="stream">The stream to deserialize.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<T> DeserializeCollection<T>(string contentType, Stream stream, ParsableFactory<T> parsableFactory) where T : IParsable
{
if(string.IsNullOrEmpty(contentType)) throw new ArgumentNullException(nameof(contentType));
Expand All @@ -115,6 +122,7 @@ public static IEnumerable<T> DeserializeCollection<T>(string contentType, Stream
/// <param name="serializedRepresentation">The serialized representation of the objects.</param>
/// <param name="parsableFactory">The factory to create the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static IEnumerable<T> DeserializeCollection<T>(string contentType, string serializedRepresentation, ParsableFactory<T> parsableFactory) where T : IParsable
{
if(string.IsNullOrEmpty(serializedRepresentation)) throw new ArgumentNullException(nameof(serializedRepresentation));
Expand All @@ -127,6 +135,7 @@ public static IEnumerable<T> DeserializeCollection<T>(string contentType, string
/// <param name="contentType">The content type of the stream.</param>
/// <param name="stream">The stream to deserialize.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static IEnumerable<T> DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, Stream stream) where T : IParsable
#else
Expand All @@ -139,6 +148,7 @@ public static IEnumerable<T> DeserializeCollection<T>(string contentType, Stream
/// <param name="contentType">The content type of the stream.</param>
/// <param name="serializedRepresentation">The serialized representation of the object.</param>
[Obsolete("Use DeserializeCollectionAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
#if NET5_0_OR_GREATER
public static IEnumerable<T> DeserializeCollection<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T>(string contentType, string serializedRepresentation) where T : IParsable
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static Stream SerializeAsStream<T>(string contentType, T value, bool seri
/// <param name="value">The object to serialize.</param>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use the async method instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static string SerializeAsString<T>(string contentType, T value) where T : IParsable
{
using var stream = SerializeAsStream(contentType, value);
Expand Down Expand Up @@ -97,6 +98,7 @@ public static Stream SerializeAsStream<T>(string contentType, IEnumerable<T> val
/// <param name="value">The object to serialize.</param>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use the async method instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static string SerializeAsString<T>(string contentType, IEnumerable<T> value) where T : IParsable
{
using var stream = SerializeAsStream(contentType, value);
Expand Down
2 changes: 2 additions & 0 deletions src/abstractions/serialization/ParseNodeFactoryRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -43,6 +44,7 @@ public string ValidContentType
/// <param name="content">The <see cref="Stream"/> to parse</param>
/// <returns></returns>
[Obsolete("Use GetRootParseNodeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public IParseNode GetRootParseNode(string contentType, Stream content)
{
if(string.IsNullOrEmpty(contentType))
Expand Down
2 changes: 2 additions & 0 deletions src/abstractions/serialization/ParseNodeProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -40,6 +41,7 @@ protected ParseNodeProxyFactory(IParseNodeFactory concrete, Action<IParsable> on
/// <param name="contentType">The content type of the parse node.</param>
/// <returns>A parse node.</returns>
[Obsolete("Use GetRootParseNodeAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public IParseNode GetRootParseNode(string contentType, Stream content)
{
var node = _concrete.GetRootParseNode(contentType, content);
Expand Down
Loading

0 comments on commit 87fba64

Please sign in to comment.