From a76a2f9d57726618f1edc8ef6f33e19416ad9841 Mon Sep 17 00:00:00 2001 From: Bastian Eicher Date: Tue, 3 Oct 2023 12:50:37 +0200 Subject: [PATCH] Moved System.Text.Json support to separate library --- README.md | 4 ++++ doc/index.md | 4 ++++ .../Serializers/SystemTextJsonSerializer.cs | 3 +++ .../TypedRest.SystemTextJson.csproj | 23 +++++++++++++++++++ src/TypedRest.sln | 6 +++++ src/TypedRest/TypedRest.csproj | 1 - src/UnitTests/UnitTests.csproj | 1 + 7 files changed, 41 insertions(+), 1 deletion(-) rename src/{TypedRest => TypedRest.SystemTextJson}/Serializers/SystemTextJsonSerializer.cs (93%) create mode 100644 src/TypedRest.SystemTextJson/TypedRest.SystemTextJson.csproj diff --git a/README.md b/README.md index 01a0d244..2e1f8991 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,10 @@ The main TypedRest library. Adds support for streaming with [ReactiveX (Rx)](http://reactivex.io/). Create endpoints using the types in the `TypedRest.Endpoints.Reactive` namespace. +[![TypedRest.SystemTextJson](https://img.shields.io/nuget/v/TypedRest.SystemTextJson.svg?label=TypedRest.SystemTextJson)](https://www.nuget.org/packages/TypedRest.Reactive/) +Adds support for serializing using [System.Text.Json](https://learn.microsoft.com/en-us/dotnet/api/system.text.json) instead of [Newtonsoft.Json](https://www.newtonsoft.com/json). +Pass `new SystemTextJsonSerializer()` to the `EntryEndpoint` constructor. + [![TypedRest.OAuth](https://img.shields.io/nuget/v/TypedRest.OAuth.svg?label=TypedRest.OAuth)](https://www.nuget.org/packages/TypedRest.OAuth/) Adds support for [OAuth 2.0](https://oauth.net/2/) / [OpenID Connect](https://openid.net/connect/) authentication to [HttpClient](https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient). Call `.AddOAuthHandler()` after `.AddTypedRest()` (or `.AddHttpClient()` when not using main TypedRest package). diff --git a/doc/index.md b/doc/index.md index 3ab36899..457c7f17 100644 --- a/doc/index.md +++ b/doc/index.md @@ -42,6 +42,10 @@ The main TypedRest library. Adds support for streaming with [ReactiveX (Rx)](http://reactivex.io/). Create endpoints using the types in the namespace. +[TypedRest.SystemTextJson](https://www.nuget.org/packages/TypedRest.SystemTextJson/) +Adds support for serializing using [System.Text.Json](https://learn.microsoft.com/en-us/dotnet/api/system.text.json) instead of [Newtonsoft.Json](https://www.newtonsoft.com/json). +Pass a instance to the constructor. + [TypedRest.OAuth](https://www.nuget.org/packages/TypedRest.OAuth/) Adds support for [OAuth 2.0](https://oauth.net/2/) / [OpenID Connect](https://openid.net/connect/) authentication to . Call `.AddOAuthHandler()` after `.AddTypedRest()` (or `.AddHttpClient()` when not using main TypedRest package). diff --git a/src/TypedRest/Serializers/SystemTextJsonSerializer.cs b/src/TypedRest.SystemTextJson/Serializers/SystemTextJsonSerializer.cs similarity index 93% rename from src/TypedRest/Serializers/SystemTextJsonSerializer.cs rename to src/TypedRest.SystemTextJson/Serializers/SystemTextJsonSerializer.cs index 4a4ef074..803834ba 100644 --- a/src/TypedRest/Serializers/SystemTextJsonSerializer.cs +++ b/src/TypedRest.SystemTextJson/Serializers/SystemTextJsonSerializer.cs @@ -1,3 +1,4 @@ +using System.Net.Http.Formatting; using System.Text.Json; using System.Text.Json.Serialization; @@ -6,6 +7,8 @@ namespace TypedRest.Serializers; /// /// Handles serializing/deserializing from/to JSON using . /// Uses camel-case naming and does not serialize null by default. +/// +/// **NuGet:** [TypedRest.SystemTextJson](https://www.nuget.org/packages/TypedRest.SystemTextJson/) /// public class SystemTextJsonSerializer : MediaTypeFormatter { diff --git a/src/TypedRest.SystemTextJson/TypedRest.SystemTextJson.csproj b/src/TypedRest.SystemTextJson/TypedRest.SystemTextJson.csproj new file mode 100644 index 00000000..9bfb9352 --- /dev/null +++ b/src/TypedRest.SystemTextJson/TypedRest.SystemTextJson.csproj @@ -0,0 +1,23 @@ + + + + + TypedRest + System.Text.Json support for TypedRest + Adds support for serializing using System.Text.Json to TypedRest. Pass new SystemTextJsonSerializer() to the EntryEndpoint constructor. + REST;Client;Type-safe;JSON;Serializer;System.Text.JSON + ..\..\artifacts\$(Configuration)\ + + + enable + + + + + + + + + + + diff --git a/src/TypedRest.sln b/src/TypedRest.sln index f5214a3b..09b3a30c 100644 --- a/src/TypedRest.sln +++ b/src/TypedRest.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypedRest", "TypedRest\Type EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypedRest.Reactive", "TypedRest.Reactive\TypedRest.Reactive.csproj", "{A9A75ECC-93CA-4055-AFD5-6E7BA5826939}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypedRest.SystemTextJson", "TypedRest.SystemTextJson\TypedRest.SystemTextJson.csproj", "{23D25AF5-4D22-4062-BCBE-3A87BF97BBA7}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypedRest.OAuth", "TypedRest.OAuth\TypedRest.OAuth.csproj", "{178420C1-3E4F-4445-BE5F-F97B7ED30FB7}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypedRest.CommandLine", "TypedRest.CommandLine\TypedRest.CommandLine.csproj", "{0EBBB26C-3F15-43A1-90AA-2A738CD1E299}" @@ -32,6 +34,10 @@ Global {A9A75ECC-93CA-4055-AFD5-6E7BA5826939}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9A75ECC-93CA-4055-AFD5-6E7BA5826939}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9A75ECC-93CA-4055-AFD5-6E7BA5826939}.Release|Any CPU.Build.0 = Release|Any CPU + {23D25AF5-4D22-4062-BCBE-3A87BF97BBA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23D25AF5-4D22-4062-BCBE-3A87BF97BBA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23D25AF5-4D22-4062-BCBE-3A87BF97BBA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23D25AF5-4D22-4062-BCBE-3A87BF97BBA7}.Release|Any CPU.Build.0 = Release|Any CPU {178420C1-3E4F-4445-BE5F-F97B7ED30FB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {178420C1-3E4F-4445-BE5F-F97B7ED30FB7}.Debug|Any CPU.Build.0 = Debug|Any CPU {178420C1-3E4F-4445-BE5F-F97B7ED30FB7}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/TypedRest/TypedRest.csproj b/src/TypedRest/TypedRest.csproj index 9736eca9..43f50cf0 100644 --- a/src/TypedRest/TypedRest.csproj +++ b/src/TypedRest/TypedRest.csproj @@ -20,7 +20,6 @@ - diff --git a/src/UnitTests/UnitTests.csproj b/src/UnitTests/UnitTests.csproj index 5987a25f..d7100486 100644 --- a/src/UnitTests/UnitTests.csproj +++ b/src/UnitTests/UnitTests.csproj @@ -20,6 +20,7 @@ +