Created
January 7, 2026 19:47
-
-
Save AnthonyGiretti/6e64c1817f181e3ac53e0fd78c8d9af2 to your computer and use it in GitHub Desktop.
.NET 10 System.Text.Json and PipeReader support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.IO.Pipelines; | |
| using System.Text.Json; | |
| // Produce JSON into a pipeline | |
| var pipe = new Pipe(); | |
| _ = Task.Run(async () => | |
| { | |
| await JsonSerializer.SerializeAsync(pipe.Writer, new Person("Alice")); | |
| await pipe.Writer.CompleteAsync(); | |
| }); | |
| await pipe.Writer.CompleteAsync(); | |
| // Consume JSON directly from PipeReader | |
| Person? person = await JsonSerializer.DeserializeAsync<Person>(pipe.Reader); | |
| Console.WriteLine(person?.Name); // "Alice" | |
| public record Person(string Name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment