-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UserProfile.Fields left empty when deserializing an empty array
Fixes #15
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
|
||
namespace SlackNet | ||
{ | ||
class IgnoreArrayConverter : JsonConverter | ||
{ | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
serializer.Serialize(writer, value); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
if (reader.TokenType == JsonToken.StartArray) | ||
{ | ||
reader.Skip(); | ||
return existingValue; | ||
} | ||
|
||
return serializer.Deserialize(reader, objectType); | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return typeof(IDictionary<,>).GetTypeInfo().IsAssignableFrom(objectType.GetTypeInfo()); | ||
} | ||
} | ||
} |