-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #560 Search crawler no longer works
- Loading branch information
Showing
6 changed files
with
71 additions
and
18 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
33 changes: 33 additions & 0 deletions
33
src/TumblThree/TumblThree.Applications/Converter/EmptyArrayOrDictionaryConverter.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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json.Linq; | ||
using Newtonsoft.Json; | ||
|
||
namespace TumblThree.Applications.Converter | ||
{ | ||
// this a modified version of this SO-answer: https://stackoverflow.com/a/45505097/14072498 | ||
public class EmptyArrayOrDictionaryConverter : JsonConverter | ||
{ | ||
public override bool CanConvert(Type objectType) => objectType.IsAssignableFrom(typeof(Dictionary<string, object>)); | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
var token = JToken.Load(reader); | ||
switch (token.Type) | ||
{ | ||
case JTokenType.Object: | ||
return token.ToObject(objectType, serializer); | ||
|
||
case JTokenType.Array: | ||
if (!token.HasValues) | ||
return Activator.CreateInstance(objectType); | ||
else | ||
throw new JsonSerializationException("Object or empty array expected"); | ||
default: | ||
throw new JsonSerializationException("Object or empty array expected"); | ||
} | ||
} | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => serializer.Serialize(writer, value); | ||
} | ||
} |
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