問題
在 Abp AppService 中回傳的物件如果有 recursion 的狀況,像是取回 PermissionGroupDefinition
,會包含 List<PermissionDefinition>
,而 PermissionDefinition
又會包含 List<PermissionDefinition>
,所以就會出現以下的錯誤,
1 | [ERR] A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.Permissions.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children.Parent.Children. |
解法
參考Adding configuration for JSON serializer providers doesn’t work,在 Web 專案的 Module 檔案中,加入以下的設定就可以正常運作。
1 | Configure<Microsoft.AspNetCore.Mvc.JsonOptions>(options => |
參考資源
Adding configuration for JSON serializer providers doesn’t work