Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
#if UNITY_EDITOR
#endif

Expand All @@ -35,6 +36,24 @@ internal class ConverterGrouping
public List<Type> unityConverters { get; set; }
public List<Type> jsonNetConverters { get; set; }

/// <summary>
/// List of converter types that should be excluded from automatic registration
/// to prevent circular references or stack overflows.
/// </summary>
private static readonly HashSet<string> ExcludedConverterTypes = new HashSet<string>
{
"Unity.ProjectAuditor.Editor.Core.DescriptorJsonConverter"
};

/// <summary>
/// List of namespace patterns that should be excluded from automatic registration
/// to prevent circular references or stack overflows.
/// </summary>
private static readonly HashSet<string> ExcludedNamespacePatterns = new HashSet<string>
{
"Unity.ProjectAuditor"
};

public static ConverterGrouping Create(IEnumerable<Type> types)
{
var grouping = new ConverterGrouping {
Expand All @@ -45,6 +64,12 @@ public static ConverterGrouping Create(IEnumerable<Type> 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);
Expand All @@ -61,5 +86,38 @@ public static ConverterGrouping Create(IEnumerable<Type> types)

return grouping;
}

/// <summary>
/// Checks if a converter type should be excluded from automatic registration.
/// </summary>
/// <param name="converterType">The converter type to check.</param>
/// <returns>True if the converter should be excluded, false otherwise.</returns>
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;
}
}
}