-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LinkPickerMode is now properly serialized when using JSON.net
By default, an enum value will be serialized to a numeric value. The mode is now serialized to a lowercase string instead - eg. "content" or "url".
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Skybrud.LinkPicker/Json/Converters/LinkPickerEnumConverter.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Skybrud.LinkPicker.Json.Converters { | ||
|
||
public class LinkPickerEnumConverter : JsonConverter { | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { | ||
|
||
if (value == null) { | ||
writer.WriteNull(); | ||
return; | ||
} | ||
|
||
writer.WriteValue((value + "").ToLower()); | ||
|
||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override bool CanConvert(Type objectType) { | ||
return objectType == typeof(Enum); | ||
} | ||
|
||
} | ||
|
||
} |
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