-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding to JsonNetSerializer ctor accepting JsonSerializer #120
Changes from 5 commits
f5aed9c
0858a8b
8639bf2
033f7b3
68fbcd7
4b641db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=HMACSHA/@EntryIndexedValue">HMACSHA</s:String> | ||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RS/@EntryIndexedValue">RS</s:String> | ||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=69CA6CF3E63C5943A86891A91C864D7C/@KeyIndexDefined">True</s:Boolean> | ||
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=69CA6CF3E63C5943A86891A91C864D7C/RelativePath/@EntryValue">JWT.sln.DotSettings</s:String> | ||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File69CA6CF3E63C5943A86891A91C864D7C/@KeyIndexDefined">True</s:Boolean> | ||
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File69CA6CF3E63C5943A86891A91C864D7C/RelativePriority/@EntryValue">1</s:Double> | ||
</wpf:ResourceDictionary> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using Newtonsoft.Json; | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace JWT.Serializers | ||
|
@@ -8,22 +9,34 @@ namespace JWT.Serializers | |
/// </summary> | ||
public sealed class JsonNetSerializer : IJsonSerializer | ||
{ | ||
private readonly JsonSerializer _serializer; | ||
|
||
/// <summary> | ||
/// Serialize the given object. | ||
/// Creates a new instance of <see cref="JsonNetSerializer" />. | ||
/// </summary> | ||
/// <param name="obj">The object to serialize.</param> | ||
/// <returns></returns> | ||
public string Serialize(object obj) | ||
/// <remarks>Uses <see cref="JsonSerializer.CreateDefault()" /> as internal serializer.</remarks> | ||
public JsonNetSerializer() | ||
: this(JsonSerializer.CreateDefault()) | ||
{ | ||
return JObject.FromObject(obj).ToString(Formatting.None); | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Deserialize the given string. | ||
/// Creates a new instance of <see cref="JsonNetSerializer" />. | ||
/// </summary> | ||
/// <typeparam name="T">The type to deserialize the string to.</typeparam> | ||
/// <param name="json">The JSON to be deserialized.</param> | ||
/// <returns></returns> | ||
/// <param name="serializer">Internal <see cref="JsonSerializer" /> to use for serialization.</param> | ||
public JsonNetSerializer(JsonSerializer serializer) | ||
{ | ||
_serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public string Serialize(object obj) | ||
{ | ||
return JObject.FromObject(obj, _serializer).ToString(Formatting.None); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IDK. Can you please try with your settings and see whether it works? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PureKrome ping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Appols - RL > everything else right now. I'll give it a crack, tonight. watch this space :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abatishchev I feel like the formatting is ignored during the so ...
BUT! because of me checking out that overload in the
This is me testing various permutations over the last 30-60 mins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh . that said ... I couldn't find an online token decoder that RESPECTED the json formatting which was encoded into the JWT. All the online decoders I think formatted the json nicely for me (which makes all of this testing, hardish) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check it out now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This LGTM 👍 I'm hoping the additions are actually worth it to other people 😊 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One can only hope :-D |
||
} | ||
|
||
/// <inheritdoc /> | ||
public T Deserialize<T>(string json) | ||
{ | ||
return JObject.Parse(json).ToObject<T>(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL:
inheritdoc
👍