Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving serialization #311

Merged
merged 12 commits into from
Aug 20, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ 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="useBackingStore">Backing store keeps track of changes, setting this to false will give you the full item.</param>
svrooij marked this conversation as resolved.
Show resolved Hide resolved
/// <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 useBackingStore = true) where T : IParsable
=> KiotaSerializer.SerializeAsStream(_jsonContentType, value, useBackingStore);

/// <summary>
/// Serializes the specified object as a string based JSON stream.
/// </summary>
/// <typeparam name="T">The type of the value to serialize.</typeparam>
/// <param name="value">The object to serialize.</param>
/// <param name="useBackingStore">A flag indicating whether to use a backing store for serialization.</param>
/// <returns>A <see cref="Stream"/> containing the serialized JSON data.</returns>

public static Stream SerializeAsJsonStream<T>(this T value, bool useBackingStore = true) where T : IParsable
svrooij marked this conversation as resolved.
Show resolved Hide resolved
=> SerializeAsStream(value, useBackingStore);

/// <summary>
/// Serializes the given object into a string based on the content type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ public static partial class KiotaSerializer
/// <typeparam name="T">Type of the object to serialize</typeparam>
/// <param name="contentType">Content type to serialize the object to </param>
/// <param name="value">The object to serialize.</param>
/// <param name="useBackingStore">Backing store keeps track of changes, setting this to false will give you the full item.</param>
/// <returns>The serialized representation as a stream.</returns>
public static Stream SerializeAsStream<T>(string contentType, T value) where T : IParsable
public static Stream SerializeAsStream<T>(string contentType, T value, bool useBackingStore = true) where T : IParsable
{
using var writer = GetSerializationWriter(contentType, value);
writer.WriteObjectValue(string.Empty, value);
writer.WriteObjectValue(useBackingStore ? string.Empty : null, value);
svrooij marked this conversation as resolved.
Show resolved Hide resolved
return writer.GetSerializedContent();
}
/// <summary>
Expand Down