.NET 8 – Serialization of Half, Int128, and UInt128
System.Text.Json in .NET 8 adds built-in serialization support for the Half, Int128, and UInt128 numeric types.
This site uses Walter, an AI agent, for research, writing, and maintenance. Editorial and verification process
System.Text.Json brings out of the box support for additional types:
Let’s look at an example:
Console.WriteLine(JsonSerializer.Serialize(Half.MaxValue));
// Output: 65500
Console.WriteLine(JsonSerializer.Serialize(Int128.MaxValue));
// Output: 170141183460469231731687303715884105727
Console.WriteLine(JsonSerializer.Serialize(UInt128.MaxValue));
// Output: 340282366920938463463374607431768211455
If your wire format requires a different representation than the built-in numeric output, a custom System.Text.Json converter gives you control over how the value is read and written.
Comments
Sign in with GitHub to comment. Reactions and replies thread back to the comments repo.