forked from jwt-dotnet/jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Day
committed
May 15, 2015
1 parent
23e3c0c
commit 08430d0
Showing
10 changed files
with
265 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Newtonsoft.Json; | ||
using JsonSerializer = ServiceStack.Text.JsonSerializer; | ||
|
||
namespace JWT.Tests | ||
{ | ||
public class ServiceStackJsonSerializer : IJsonSerializer | ||
{ | ||
public string Serialize(object obj) | ||
{ | ||
return JsonSerializer.SerializeToString(obj); | ||
} | ||
|
||
public T Deserialize<T>(string json) | ||
{ | ||
return JsonSerializer.DeserializeFromString<T>(json); | ||
} | ||
} | ||
|
||
public class NewtonJsonSerializer : IJsonSerializer | ||
{ | ||
public string Serialize(object obj) | ||
{ | ||
return JsonConvert.SerializeObject(obj); | ||
} | ||
|
||
public T Deserialize<T>(string json) | ||
{ | ||
return JsonConvert.DeserializeObject<T>(json); | ||
} | ||
} | ||
} |
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="FluentAssertions" version="3.3.0" targetFramework="net451" /> | ||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net451" /> | ||
<package id="ServiceStack.Text" version="4.0.40" targetFramework="net451" /> | ||
</packages> |
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,33 @@ | ||
using System.Web.Script.Serialization; | ||
|
||
namespace JWT | ||
{ | ||
/// <summary> | ||
/// JSON Serializer using JavaScriptSerializer | ||
/// </summary> | ||
public class DefaultJsonSerializer : IJsonSerializer | ||
{ | ||
private readonly JavaScriptSerializer serializer = new JavaScriptSerializer(); | ||
|
||
/// <summary> | ||
/// Serialize an object to JSON string | ||
/// </summary> | ||
/// <param name="obj">object</param> | ||
/// <returns>JSON string</returns> | ||
public string Serialize(object obj) | ||
{ | ||
return serializer.Serialize(obj); | ||
} | ||
|
||
/// <summary> | ||
/// Deserialize a JSON string to typed object. | ||
/// </summary> | ||
/// <typeparam name="T">type of object</typeparam> | ||
/// <param name="json">JSON string</param> | ||
/// <returns>typed object</returns> | ||
public T Deserialize<T>(string json) | ||
{ | ||
return serializer.Deserialize<T>(json); | ||
} | ||
} | ||
} |
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,23 @@ | ||
namespace JWT | ||
{ | ||
/// <summary> | ||
/// Provides JSON Serialize and Deserialize. Allows custom serializers used. | ||
/// </summary> | ||
public interface IJsonSerializer | ||
{ | ||
/// <summary> | ||
/// Serialize an object to JSON string | ||
/// </summary> | ||
/// <param name="obj">object</param> | ||
/// <returns>JSON string</returns> | ||
string Serialize(object obj); | ||
|
||
/// <summary> | ||
/// Deserialize a JSON string to typed object. | ||
/// </summary> | ||
/// <typeparam name="T">type of object</typeparam> | ||
/// <param name="json">JSON string</param> | ||
/// <returns>typed object</returns> | ||
T Deserialize<T>(string json); | ||
} | ||
} |
Oops, something went wrong.