public static async Task SerializeAsync( Stream stream, JsonSchemaResource resource, JsonSerializerOptions?options = null, CancellationToken cancellationToken = default) { CheckValue(stream, nameof(stream)); CheckValue(resource, nameof(resource)); using (var schemaWriter = new JsonSchemaWriter(stream, options)) { schemaWriter.Write(resource); await schemaWriter.FlushAsync(cancellationToken); } }
public static string Serialize( JsonSchemaResource resource, JsonSerializerOptions?options = null) { CheckValue(resource, nameof(resource)); using (var stream = MemoryStreamManager.GetStream()) using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8)) using (var writer = new JsonSchemaWriter(stream, options)) { writer.Write(resource); writer.Flush(); stream.Position = 0; return(reader.ReadToEnd()); } }