diff --git a/Packages/Newtonsoft.Json-for-Unity.Converters/UnityConverters/ConverterGrouping.cs b/Packages/Newtonsoft.Json-for-Unity.Converters/UnityConverters/ConverterGrouping.cs index c0c93b5..79239bb 100644 --- a/Packages/Newtonsoft.Json-for-Unity.Converters/UnityConverters/ConverterGrouping.cs +++ b/Packages/Newtonsoft.Json-for-Unity.Converters/UnityConverters/ConverterGrouping.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; +using System.Linq; #if UNITY_EDITOR #endif @@ -35,6 +36,24 @@ internal class ConverterGrouping public List unityConverters { get; set; } public List jsonNetConverters { get; set; } + /// + /// List of converter types that should be excluded from automatic registration + /// to prevent circular references or stack overflows. + /// + private static readonly HashSet ExcludedConverterTypes = new HashSet + { + "Unity.ProjectAuditor.Editor.Core.DescriptorJsonConverter" + }; + + /// + /// List of namespace patterns that should be excluded from automatic registration + /// to prevent circular references or stack overflows. + /// + private static readonly HashSet ExcludedNamespacePatterns = new HashSet + { + "Unity.ProjectAuditor" + }; + public static ConverterGrouping Create(IEnumerable types) { var grouping = new ConverterGrouping { @@ -45,6 +64,12 @@ public static ConverterGrouping Create(IEnumerable types) foreach (var converter in types) { + // Skip excluded converter types to prevent circular references + if (IsExcludedConverter(converter)) + { + continue; + } + if (converter.Namespace?.StartsWith("Newtonsoft.Json.UnityConverters") == true) { grouping.unityConverters.Add(converter); @@ -61,5 +86,38 @@ public static ConverterGrouping Create(IEnumerable types) return grouping; } + + /// + /// Checks if a converter type should be excluded from automatic registration. + /// + /// The converter type to check. + /// True if the converter should be excluded, false otherwise. + private static bool IsExcludedConverter(Type converterType) + { + if (converterType?.FullName == null) + { + return false; + } + + // Check exact type name exclusions + if (ExcludedConverterTypes.Contains(converterType.FullName)) + { + return true; + } + + // Check namespace pattern exclusions + if (converterType.Namespace != null) + { + foreach (var excludedPattern in ExcludedNamespacePatterns) + { + if (converterType.Namespace.StartsWith(excludedPattern)) + { + return true; + } + } + } + + return false; + } } }