Making edit routes kinda work

This commit is contained in:
Zoe Roux
2020-12-24 18:49:34 +01:00
parent 5229e319b1
commit 41cabdd1b5
21 changed files with 78 additions and 71 deletions
+13 -12
View File
@@ -13,7 +13,19 @@ using Newtonsoft.Json.Serialization;
namespace Kyoo.Controllers
{
public class JsonPropertySelector : CamelCasePropertyNamesContractResolver
public class JsonPropertyIgnorer : CamelCasePropertyNamesContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
JsonProperty property = base.CreateProperty(member, memberSerialization);
property.ShouldSerialize = i => member.GetCustomAttribute<JsonReadOnly>(true) == null;
property.ShouldDeserialize = i => member.GetCustomAttribute<JsonIgnore>(true) == null;
return property;
}
}
public class JsonPropertySelector : JsonPropertyIgnorer
{
private readonly Dictionary<Type, HashSet<string>> _ignored;
private readonly Dictionary<Type, HashSet<string>> _forceSerialize;
@@ -60,20 +72,9 @@ namespace Kyoo.Controllers
JsonProperty property = base.CreateProperty(member, memberSerialization);
if (IsSerializationForced(property.DeclaringType, property.PropertyName))
{
property.ShouldSerialize = i => true;
property.Ignored = false;
}
else if (IsIgnored(property.DeclaringType, property.PropertyName))
{
property.ShouldSerialize = i => false;
property.Ignored = true;
}
else
{
property.ShouldSerialize = i => member.GetCustomAttribute<JsonReadOnly>(true) == null;
property.ShouldDeserialize = i => member.GetCustomAttribute<JsonIgnore>(true) == null;
}
return property;
}
}