From f5aed9c988f30c47232adc036215246bb85ecc96 Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Fri, 23 Jun 2017 11:55:26 -0700 Subject: [PATCH 1/6] Adding to JsonNetSerializer ctor accepting JsonSerializer --- src/JWT/Serializers/JsonNetSerializer.cs | 26 ++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/JWT/Serializers/JsonNetSerializer.cs b/src/JWT/Serializers/JsonNetSerializer.cs index 20a34360a..4ba03d8eb 100644 --- a/src/JWT/Serializers/JsonNetSerializer.cs +++ b/src/JWT/Serializers/JsonNetSerializer.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace JWT.Serializers @@ -8,6 +9,27 @@ namespace JWT.Serializers /// public sealed class JsonNetSerializer : IJsonSerializer { + private readonly JsonSerializer _serializer; + + /// + /// Creates a new instance of . + /// + /// Uses as internal serializer. + public JsonNetSerializer() + : this(JsonSerializer.CreateDefault()) + { + + } + + /// + /// Creates a new instance of . + /// + /// Internal to use for serialization. + public JsonNetSerializer(JsonSerializer serializer) + { + _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); + } + /// /// Serialize the given object. /// @@ -15,7 +37,7 @@ public sealed class JsonNetSerializer : IJsonSerializer /// public string Serialize(object obj) { - return JObject.FromObject(obj).ToString(Formatting.None); + return JObject.FromObject(obj, _serializer).ToString(Formatting.None); } /// From 0858a8b072ee0297e9f5e5c87b555583086df08e Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Fri, 23 Jun 2017 11:55:59 -0700 Subject: [PATCH 2/6] Removing the beta prefix from nuget version --- src/JWT/JWT.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JWT/JWT.csproj b/src/JWT/JWT.csproj index e82e617c8..d9e491655 100644 --- a/src/JWT/JWT.csproj +++ b/src/JWT/JWT.csproj @@ -21,7 +21,7 @@ https://github.com/jwt-dotnet/jwt John Sheehan, Michael Lehenbauer, Alexander Batishchev https://creativecommons.org/publicdomain/zero/1.0/ - 3.0.0-beta4 + 3.0.0 jwt json From 8639bf231bd0d2a1fb558bc2bc9041b497a762df Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Fri, 23 Jun 2017 12:01:54 -0700 Subject: [PATCH 3/6] Replacing xml docs on methods with --- src/JWT/Serializers/JsonNetSerializer.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/JWT/Serializers/JsonNetSerializer.cs b/src/JWT/Serializers/JsonNetSerializer.cs index 4ba03d8eb..26578ebc5 100644 --- a/src/JWT/Serializers/JsonNetSerializer.cs +++ b/src/JWT/Serializers/JsonNetSerializer.cs @@ -30,22 +30,13 @@ public JsonNetSerializer(JsonSerializer serializer) _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); } - /// - /// Serialize the given object. - /// - /// The object to serialize. - /// + /// public string Serialize(object obj) { return JObject.FromObject(obj, _serializer).ToString(Formatting.None); } - /// - /// Deserialize the given string. - /// - /// The type to deserialize the string to. - /// The JSON to be deserialized. - /// + /// public T Deserialize(string json) { return JObject.Parse(json).ToObject(); From 033f7b3ff774577d783d9e223bc11d8b9714b440 Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Fri, 23 Jun 2017 12:03:57 -0700 Subject: [PATCH 4/6] Soring usings in tests --- tests/JWT.Tests.Common/JwtDecoderTest.cs | 2 +- tests/JWT.Tests.Common/JwtEncoderTest.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/JWT.Tests.Common/JwtDecoderTest.cs b/tests/JWT.Tests.Common/JwtDecoderTest.cs index 5ca36046c..25a455c34 100644 --- a/tests/JWT.Tests.Common/JwtDecoderTest.cs +++ b/tests/JWT.Tests.Common/JwtDecoderTest.cs @@ -2,8 +2,8 @@ using FluentAssertions; using JWT.Algorithms; using JWT.Serializers; -using Xunit; using JWT.Tests.Common; +using Xunit; namespace JWT.Tests { diff --git a/tests/JWT.Tests.Common/JwtEncoderTest.cs b/tests/JWT.Tests.Common/JwtEncoderTest.cs index c2b88044a..280ecba37 100644 --- a/tests/JWT.Tests.Common/JwtEncoderTest.cs +++ b/tests/JWT.Tests.Common/JwtEncoderTest.cs @@ -2,8 +2,8 @@ using FluentAssertions; using JWT.Algorithms; using JWT.Serializers; -using Xunit; using JWT.Tests.Common; +using Xunit; namespace JWT.Tests { From 68fbcd72024357707482fb9a09bd5a0116249d72 Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Fri, 23 Jun 2017 12:04:09 -0700 Subject: [PATCH 5/6] Updating R# settings files --- JWT.sln.DotSettings | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/JWT.sln.DotSettings b/JWT.sln.DotSettings index a015806f3..288827a8e 100644 --- a/JWT.sln.DotSettings +++ b/JWT.sln.DotSettings @@ -1,4 +1,8 @@  HMACSHA RS + True + JWT.sln.DotSettings + True + 1 \ No newline at end of file From 4b641dbe04fe1436b9b7098730244115eb1dca7b Mon Sep 17 00:00:00 2001 From: Alex Batishchev Date: Wed, 28 Jun 2017 13:26:34 -0700 Subject: [PATCH 6/6] Using _serializer.Formatting, _serializer.Converters in Serialize(), Deserialize() --- src/JWT/Serializers/JsonNetSerializer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/JWT/Serializers/JsonNetSerializer.cs b/src/JWT/Serializers/JsonNetSerializer.cs index 26578ebc5..f305f31b9 100644 --- a/src/JWT/Serializers/JsonNetSerializer.cs +++ b/src/JWT/Serializers/JsonNetSerializer.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -33,13 +34,13 @@ public JsonNetSerializer(JsonSerializer serializer) /// public string Serialize(object obj) { - return JObject.FromObject(obj, _serializer).ToString(Formatting.None); + return JObject.FromObject(obj, _serializer).ToString(_serializer.Formatting, _serializer.Converters.ToArray()); } /// public T Deserialize(string json) { - return JObject.Parse(json).ToObject(); + return JObject.Parse(json).ToObject(_serializer); } } } \ No newline at end of file