using System.Text.Json; namespace MycroForge.Core.Extensions; public static class ObjectStreamExtensions { public static async Task SerializeAsync( this object @object, JsonSerializerOptions? jsonSerializerOptions = null ) { using var stream = new MemoryStream(); using var reader = new StreamReader(stream); var options = jsonSerializerOptions ?? Serialization.DefaultJsonSerializerOptions.Default; await JsonSerializer.SerializeAsync(stream, @object, options); stream.Position = 0; return await reader.ReadToEndAsync(); } }