Last active
January 7, 2026 20:02
-
-
Save AnthonyGiretti/83f0e311820cdc32286efb0e38ec1fdd to your computer and use it in GitHub Desktop.
Before .NET 10 System.Text.Json and deserilization from Stream
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; | |
| var pipe = new Pipe(); | |
| _ = Task.Run(async () => | |
| { | |
| try | |
| { | |
| await JsonSerializer.SerializeAsync(pipe.Writer, new Person("Alice")); | |
| await pipe.Writer.FlushAsync(); | |
| } | |
| finally | |
| { | |
| await pipe.Writer.CompleteAsync(); | |
| } | |
| }); | |
| var stream = pipe.Reader.AsStream(); | |
| var person = await JsonSerializer.DeserializeAsync<Person>(stream); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment