mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Fix kind serialation
This commit is contained in:
parent
ad9d1ee430
commit
0c0037416a
@ -18,10 +18,8 @@
|
|||||||
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using System.Text.Json.Serialization.Metadata;
|
using System.Text.Json.Serialization.Metadata;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
using static System.Text.Json.JsonNamingPolicy;
|
using static System.Text.Json.JsonNamingPolicy;
|
||||||
@ -30,13 +28,6 @@ namespace Kyoo.Core.Api;
|
|||||||
|
|
||||||
public class PolymorphicTypeResolver : DefaultJsonTypeInfoResolver
|
public class PolymorphicTypeResolver : DefaultJsonTypeInfoResolver
|
||||||
{
|
{
|
||||||
private static readonly IList<JsonDerivedType> _types = AppDomain
|
|
||||||
.CurrentDomain.GetAssemblies()
|
|
||||||
.SelectMany(s => s.GetTypes())
|
|
||||||
.Where(p => p.IsAssignableTo(typeof(IResource)) && p.IsClass)
|
|
||||||
.Select(x => new JsonDerivedType(x, CamelCase.ConvertName(x.Name)))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
|
public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
|
||||||
{
|
{
|
||||||
JsonTypeInfo jsonTypeInfo = base.GetTypeInfo(type, options);
|
JsonTypeInfo jsonTypeInfo = base.GetTypeInfo(type, options);
|
||||||
@ -50,13 +41,14 @@ public class PolymorphicTypeResolver : DefaultJsonTypeInfoResolver
|
|||||||
{
|
{
|
||||||
TypeDiscriminatorPropertyName = "kind",
|
TypeDiscriminatorPropertyName = "kind",
|
||||||
IgnoreUnrecognizedTypeDiscriminators = true,
|
IgnoreUnrecognizedTypeDiscriminators = true,
|
||||||
UnknownDerivedTypeHandling =
|
DerivedTypes =
|
||||||
JsonUnknownDerivedTypeHandling.FallBackToNearestAncestor,
|
{
|
||||||
DerivedTypes = { },
|
new JsonDerivedType(
|
||||||
|
jsonTypeInfo.Type,
|
||||||
|
CamelCase.ConvertName(jsonTypeInfo.Type.Name)
|
||||||
|
),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
Console.WriteLine(string.Join(",", _types.Select(x => x.DerivedType.Name)));
|
|
||||||
foreach (JsonDerivedType derived in _types)
|
|
||||||
jsonTypeInfo.PolymorphismOptions.DerivedTypes.Add(derived);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonTypeInfo;
|
return jsonTypeInfo;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user