-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathKiotaJsonSerializer.Serialization.cs
106 lines (96 loc) · 6.19 KB
/
KiotaJsonSerializer.Serialization.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// ------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
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
namespace Microsoft.Kiota.Abstractions.Serialization;
public static partial class KiotaJsonSerializer
{
/// <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>(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.
/// </summary>
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="value">The object to serialize.</param>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use SerializeAsStringAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static string SerializeAsString<T>(T value) where T : IParsable
=> KiotaSerializer.SerializeAsString(_jsonContentType, value);
/// <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="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
=> 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, bool serializeOnlyChangedValues = true) where T : IParsable
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value, serializeOnlyChangedValues);
/// <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>
/// <returns>The serialized representation as a string.</returns>
[Obsolete("This method is obsolete, use SerializeAsStringAsync instead")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static string SerializeAsString<T>(IEnumerable<T> value) where T : IParsable
=> KiotaSerializer.SerializeAsString(_jsonContentType, value);
/// <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="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 =>
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);
}