-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to select serializer (#433)
* Bumped all versions * Renamed methods on JwtBuilder * Added DefaultJsonSerializerFactory * Added DelegateJsonSerializerFactory * Updated tests Co-authored-by: Markus Hartung <[email protected]> Co-authored-by: Alexander Batishchev <[email protected]>
- Loading branch information
1 parent
b387094
commit 2e2c9c0
Showing
24 changed files
with
250 additions
and
98 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
2 changes: 1 addition & 1 deletion
2
src/JWT/Serializers/Converters/DictionaryStringObjectJsonConverter.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#if SYSTEM_TEXT_JSON | ||
#if MODERN_DOTNET | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace JWT.Serializers | ||
{ | ||
public sealed class DefaultJsonSerializerFactory : IJsonSerializerFactory | ||
{ | ||
private readonly IJsonSerializer _jsonSerializer; | ||
|
||
public DefaultJsonSerializerFactory() | ||
{ | ||
#if MODERN_DOTNET | ||
_jsonSerializer = new SystemTextSerializer(); | ||
#else | ||
_jsonSerializer = new JsonNetSerializer(); | ||
#endif | ||
} | ||
|
||
public IJsonSerializer Create() => | ||
_jsonSerializer; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
|
||
namespace JWT.Serializers | ||
{ | ||
internal sealed class DelegateJsonSerializerFactory : IJsonSerializerFactory | ||
{ | ||
private readonly Func<IJsonSerializer> _factory; | ||
|
||
public DelegateJsonSerializerFactory(IJsonSerializer jsonSerializer) : | ||
this(() => jsonSerializer) | ||
{ | ||
if (jsonSerializer is null) | ||
throw new ArgumentNullException(nameof(jsonSerializer)); | ||
} | ||
|
||
public DelegateJsonSerializerFactory(IJsonSerializerFactory factory) : | ||
this(() => factory.Create()) | ||
{ | ||
if (factory is null) | ||
throw new ArgumentNullException(nameof(factory)); | ||
} | ||
|
||
public DelegateJsonSerializerFactory(Func<IJsonSerializer> factory) => | ||
_factory = factory ?? throw new ArgumentNullException(nameof(factory)); | ||
|
||
public IJsonSerializer Create() => | ||
_factory(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace JWT.Serializers | ||
{ | ||
public interface IJsonSerializerFactory | ||
{ | ||
IJsonSerializer Create(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.