AustinHarris.JsonRpc.SystemTextJson
2.0.1
dotnet add package AustinHarris.JsonRpc.SystemTextJson --version 2.0.1
NuGet\Install-Package AustinHarris.JsonRpc.SystemTextJson -Version 2.0.1
<PackageReference Include="AustinHarris.JsonRpc.SystemTextJson" Version="2.0.1" />
<PackageVersion Include="AustinHarris.JsonRpc.SystemTextJson" Version="2.0.1" />
<PackageReference Include="AustinHarris.JsonRpc.SystemTextJson" />
paket add AustinHarris.JsonRpc.SystemTextJson --version 2.0.1
#r "nuget: AustinHarris.JsonRpc.SystemTextJson, 2.0.1"
#:package AustinHarris.JsonRpc.SystemTextJson@2.0.1
#addin nuget:?package=AustinHarris.JsonRpc.SystemTextJson&version=2.0.1
#tool nuget:?package=AustinHarris.JsonRpc.SystemTextJson&version=2.0.1
AustinHarris.JsonRpc.SystemTextJson
AustinHarris.JsonRpc.SystemTextJson adds System.Text.Json serialization to
AustinHarris.JsonRpc 2.0.
Choose it when your application already uses JsonSerializerOptions and System.Text.Json converters.
Request parameters arrive as the raw UTF-8 bytes of one JSON value and go straight into JsonSerializer.Deserialize,
with no transcoding and no copies. Results are written with a per-thread cached Utf8JsonWriter directly into the
response buffer.
Install
dotnet add package AustinHarris.JsonRpc.SystemTextJson
Targets netstandard2.0, netstandard2.1, net8.0 and net10.0; depends on System.Text.Json 10.0.3 and the
AustinHarris.JsonRpc core package.
Use
Process-wide default:
using AustinHarris.JsonRpc;
using AustinHarris.JsonRpc.SystemTextJson;
Config.SetSerializer(new SystemTextJsonRpcSerializer());
// or with your own options
Config.SetSerializer(new SystemTextJsonRpcSerializer(options));
Per session:
Config.SetSerializer(sessionId, new SystemTextJsonRpcSerializer(options));
Per call (overrides both the session and the process-wide default):
var serializer = new SystemTextJsonRpcSerializer(options);
string response = JsonRpcProcessor.ProcessSync(sessionId, json, context, serializer);
// the byte-based overloads take the same trailing argument:
JsonRpcProcessor.Process(sessionId, requestBytes, outputWriter, context, serializer);
When each level is the right one is covered in docs/serializers.md.
Create one instance and reuse it. The options it actually uses (EffectiveOptions) are read-only; the object you
passed is never changed.
Default options
new SystemTextJsonRpcSerializer() uses SystemTextJsonRpcSerializer.DefaultOptions, a single immutable
JsonSerializerOptions that reproduces the wire conventions of the built-in and Json.NET serializers for the
envelope, primitives, dates and plain objects. The serializers are still not interchangeable for every request:
System.Text.Json refuses some coercions the other two accept (a JSON number sent for a string parameter, for
example), the CLR types each supports differ, and so does the object model handed to handlers. Test client-visible
requests and responses before switching.
| Setting | Value |
|---|---|
WriteIndented |
false (compact output) |
DefaultIgnoreCondition |
Never (nulls are written) |
PropertyNamingPolicy |
null (member names as declared, in declaration order) |
PropertyNameCaseInsensitive |
true |
IncludeFields |
true (public fields bind like properties) |
Encoder |
JavaScriptEncoder.UnsafeRelaxedJsonEscaping (+, <, >, & and non-ASCII text are written as they are, not Unicode-escaped) |
NumberHandling |
AllowReadingFromString |
Converters |
the JsonRpcConverters below |
Converters
Registered by JsonRpcConverters.AddMissing(options); each is public so it can be used on its own.
| Converter | Writes | Reads |
|---|---|---|
JsonRpcNumberConverterFactory (double, float, decimal, and the 8 integer types) |
whole float/double/decimal values with .0 (3.0, 71.0, 0.0), otherwise shortest round-trip (1.2345, 3.14159); NaN and the infinities as the quoted strings "NaN", "Infinity", "-Infinity", as Json.NET and the built-in serializer write them |
numbers, numeric strings, true/false as 1/0; fractional input for integer types is rounded to even |
JsonRpcBooleanConverter |
true/false |
booleans, numbers (non-zero is true), "true"/"false"/numeric strings |
JsonRpcCharConverter |
a one-character string | a one-character string or a number (98 reads as 'b') |
JsonRpcDateTimeConverter |
yyyy-MM-ddTHH:mm:ss[.fffffff]K, the fraction only when non-zero and with trailing zeros trimmed, exactly as Json.NET and the built-in serializer write it |
any ISO-8601 text via DateTime.Parse(..., InvariantCulture, RoundtripKind): an offset in the input yields a Local DateTime |
JsonRpcDateTimeOffsetConverter |
yyyy-MM-ddTHH:mm:ss[.fffffff]zzz |
ISO-8601 text |
Nullable variants (double?, DateTime?, ...) are covered automatically by System.Text.Json's nullable
wrapping. Because these converters replace the built-in numeric ones, JsonNumberHandling.WriteAsString and
AllowNamedFloatingPointLiterals are not applied to the primitive numeric types.
Supplying your own options
new SystemTextJsonRpcSerializer(options) honours the options as given (naming policy, encoder, extra
converters, TypeInfoResolver, ...). The only adjustment is the converter set:
- If
options.Convertersalready contains everyJsonRpcConverterstype, the instance is used as-is (it is made read-only, as System.Text.Json would do on first use anyway). - Otherwise the options are copied with
new JsonSerializerOptions(options)and the missing converters are appended to the copy, which is then made read-only. The object you passed is never mutated, so it is safe to share with other code. The converters are appended after yours, so a converter you registered for the same type keeps precedence.
Options returns what you passed (null for the defaults); EffectiveOptions returns the instance actually used.
To start from the library defaults and tweak them:
var options = SystemTextJsonRpcSerializer.CreateDefaultOptions(); // a mutable copy of DefaultOptions
options.Converters.Add(new JsonStringEnumConverter());
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
Config.SetSerializer(new SystemTextJsonRpcSerializer(options));
If you build options from scratch, remember that the wire conventions above (IncludeFields,
UnsafeRelaxedJsonEscaping, PropertyNameCaseInsensitive) are then up to you; only the converters are added.
Object model
Pre/post-process handlers receive JsonRequest.Params as a JsonElement (the result of deserializing the
params to object), and Handler.Handle(JsonRequest) accepts a JsonElement back.
A client value that cannot be converted to the parameter's type throws JsonException, which the core reports
as -32602 Invalid params with data naming the parameter and the expected type; the value sent is never echoed.
System.Text.Json is stricter than the other two serializers here: a JSON number sent for a string parameter is
refused. An unsupported CLR type or an internal serialization failure remains -32603 Internal error.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- AustinHarris.JsonRpc (>= 2.0.1)
- System.Text.Json (>= 10.0.3)
-
.NETStandard 2.1
- AustinHarris.JsonRpc (>= 2.0.1)
- System.Text.Json (>= 10.0.3)
-
net10.0
- AustinHarris.JsonRpc (>= 2.0.1)
-
net8.0
- AustinHarris.JsonRpc (>= 2.0.1)
- System.Text.Json (>= 10.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.1 | 91 | 9/28/2026 |
| 2.0.0 | 85 | 9/28/2026 |
| 2.0.0-preview.3 | 53 | 9/28/2026 |
| 2.0.0-preview.2 | 58 | 9/28/2026 |
| 2.0.0-preview.1 | 66 | 9/25/2026 |
2.0.1, released with the core package. What is new: https://astn.github.io/JSON-RPC.NET/changelog.html. Upgrading from 1.x: https://astn.github.io/JSON-RPC.NET/upgrading.html