diff --git a/Kyoo.Common/Models/PeopleRole.cs b/Kyoo.Common/Models/PeopleRole.cs index 533f0fca..fe027682 100644 --- a/Kyoo.Common/Models/PeopleRole.cs +++ b/Kyoo.Common/Models/PeopleRole.cs @@ -1,7 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq; -using System.Linq.Expressions; using Kyoo.Models.Attributes; namespace Kyoo.Models @@ -12,7 +9,6 @@ namespace Kyoo.Models [SerializeIgnore] public string Slug => ForPeople ? Show.Slug : People.Slug; [SerializeIgnore] public bool ForPeople; [SerializeIgnore] public int PeopleID { get; set; } - // TODO implement a SerializeInline for People or Show depending on the context. [SerializeIgnore] public virtual People People { get; set; } [SerializeIgnore] public int ShowID { get; set; } [SerializeIgnore] public virtual Show Show { get; set; } diff --git a/Kyoo.CommonAPI/JsonSerializer.cs b/Kyoo.CommonAPI/JsonSerializer.cs index 69d818ae..420ab9b8 100644 --- a/Kyoo.CommonAPI/JsonSerializer.cs +++ b/Kyoo.CommonAPI/JsonSerializer.cs @@ -4,6 +4,7 @@ using System.Reflection; using Kyoo.Models; using Kyoo.Models.Attributes; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using Newtonsoft.Json.Serialization; namespace Kyoo.Controllers @@ -52,4 +53,24 @@ namespace Kyoo.Controllers return contract; } } + + public class PeopleRoleConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, PeopleRole value, JsonSerializer serializer) + { + // TODO this seems to not use the property.ShouldSerialize and cause an recursive inclusion error. + JToken t = JToken.FromObject(value, serializer); + JObject obj = t as JObject; + writer.WriteValue(obj); + } + + public override PeopleRole ReadJson(JsonReader reader, + Type objectType, + PeopleRole existingValue, + bool hasExistingValue, + JsonSerializer serializer) + { + throw new NotImplementedException(); + } + } } \ No newline at end of file diff --git a/Kyoo/Startup.cs b/Kyoo/Startup.cs index b04a7f18..c31c51e6 100644 --- a/Kyoo/Startup.cs +++ b/Kyoo/Startup.cs @@ -43,7 +43,11 @@ namespace Kyoo }); services.AddControllers() - .AddNewtonsoftJson(x => x.SerializerSettings.ContractResolver = new JsonPropertyIgnorer()); + .AddNewtonsoftJson(x => + { + x.SerializerSettings.ContractResolver = new JsonPropertyIgnorer(); + x.SerializerSettings.Converters.Add(new PeopleRoleConverter()); + }); services.AddHttpClient(); services.AddDbContext(options => diff --git a/Kyoo/Views/API/LibraryItemApi.cs b/Kyoo/Views/API/LibraryItemApi.cs index e0ae3560..9f97a275 100644 --- a/Kyoo/Views/API/LibraryItemApi.cs +++ b/Kyoo/Views/API/LibraryItemApi.cs @@ -15,6 +15,7 @@ namespace Kyoo.Api [Route("api/item")] [Route("api/items")] [ApiController] + [ResourceView] public class LibraryItemApi : ControllerBase { private readonly ILibraryItemRepository _libraryItems;