mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Fixing the json serializer for multiple level inheritance
This commit is contained in:
parent
ff1be5c145
commit
8430f0f1d8
@ -40,11 +40,11 @@ namespace Kyoo.CommonApi
|
||||
[JsonDetailed]
|
||||
public virtual async Task<ActionResult<T>> Get(string slug)
|
||||
{
|
||||
T ressource = await _repository.Get(slug);
|
||||
if (ressource == null)
|
||||
T resource = await _repository.Get(slug);
|
||||
if (resource == null)
|
||||
return NotFound();
|
||||
|
||||
return ressource;
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
@ -32,20 +32,26 @@ namespace Kyoo.Controllers
|
||||
|
||||
private bool IsIgnored(Type type, string propertyName)
|
||||
{
|
||||
if (_ignored.ContainsKey(type) && _ignored[type].Contains(propertyName))
|
||||
return true;
|
||||
if (type.BaseType == null)
|
||||
return false;
|
||||
return _ignored.ContainsKey(type.BaseType) && _ignored[type.BaseType].Contains(propertyName);
|
||||
while (type != null)
|
||||
{
|
||||
if (_ignored.ContainsKey(type) && _ignored[type].Contains(propertyName))
|
||||
return true;
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsSerializationForced(Type type, string propertyName)
|
||||
{
|
||||
if (_forceSerialize.ContainsKey(type) && _forceSerialize[type].Contains(propertyName))
|
||||
return true;
|
||||
if (type.BaseType == null)
|
||||
return false;
|
||||
return _forceSerialize.ContainsKey(type.BaseType) && _forceSerialize[type.BaseType].Contains(propertyName);
|
||||
while (type != null)
|
||||
{
|
||||
if (_forceSerialize.ContainsKey(type) && _forceSerialize[type].Contains(propertyName))
|
||||
return true;
|
||||
type = type.BaseType;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
|
||||
@ -75,7 +81,7 @@ namespace Kyoo.Controllers
|
||||
result.Formatters.Add(new NewtonsoftJsonOutputFormatter(
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new JsonPropertySelector(null, new Dictionary<Type, HashSet<string>>()
|
||||
ContractResolver = new JsonPropertySelector(null, new Dictionary<Type, HashSet<string>>
|
||||
{
|
||||
{typeof(Show), new HashSet<string> {"genres", "studio"}},
|
||||
{typeof(Episode), new HashSet<string> {"tracks"}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user