From 467e42058795d1109a92774dc03e7be24f5b3a1a Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 27 Mar 2021 00:50:34 +0100 Subject: [PATCH] Fixing recurrent use of the json serializer with depth check --- Kyoo.CommonAPI/JsonSerializer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Kyoo.CommonAPI/JsonSerializer.cs b/Kyoo.CommonAPI/JsonSerializer.cs index c9238049..bf65a32a 100644 --- a/Kyoo.CommonAPI/JsonSerializer.cs +++ b/Kyoo.CommonAPI/JsonSerializer.cs @@ -47,6 +47,8 @@ namespace Kyoo.Controllers if (member?.GetCustomAttribute() != null) property.ShouldDeserialize = _ => false; + // TODO use http context to disable serialize as. + // TODO check https://stackoverflow.com/questions/53288633/net-core-api-custom-json-resolver-based-on-request-values SerializeAsAttribute serializeAs = member?.GetCustomAttribute(); if (serializeAs != null) property.ValueProvider = new SerializeAsProvider(serializeAs.Format, _host); @@ -57,7 +59,8 @@ namespace Kyoo.Controllers { JsonContract contract = base.CreateContract(objectType); if (Utility.GetGenericDefinition(objectType, typeof(Page<>)) == null - && !objectType.IsAssignableTo(typeof(IEnumerable))) + && !objectType.IsAssignableTo(typeof(IEnumerable)) + && objectType.Name != "AnnotatedProblemDetails") { contract.OnSerializingCallbacks.Add((_, _) => _depth++); contract.OnSerializedCallbacks.Add((_, _) => _depth--);