Skip to content

Commit

Permalink
Fix custom converter serialization again (#441)
Browse files Browse the repository at this point in the history
This time it should hopefully work.
  • Loading branch information
einarmo authored Jun 20, 2024
1 parent 334a510 commit 3d5765e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Cognite.Config/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public static string ConfigToString<T>(
toAlwaysKeep,
toIgnore,
namePrefixes,
converters,
allowReadOnly))
.WithNamingConvention(HyphenatedNamingConvention.Instance);

Expand Down Expand Up @@ -503,6 +504,7 @@ internal class DefaultFilterTypeInspector : TypeInspectorSkeleton
private readonly HashSet<string> _toAlwaysKeep;
private readonly HashSet<string> _toIgnore;
private readonly IEnumerable<string> _namePrefixes;
private readonly IEnumerable<IYamlTypeConverter> _customConverters;
private readonly bool _allowReadOnly;
/// <summary>
/// Constructor
Expand All @@ -511,19 +513,22 @@ internal class DefaultFilterTypeInspector : TypeInspectorSkeleton
/// <param name="toAlwaysKeep">Fields to always keep</param>
/// <param name="toIgnore">Fields to exclude</param>
/// <param name="namePrefixes">Prefixes on full type names for types that should be explored internally</param>
/// <param name="customConverters">List of registered custom converters.</param>
/// <param name="allowReadOnly">Allow read only properties</param>
public DefaultFilterTypeInspector(
ITypeInspector innerTypeDescriptor,
IEnumerable<string> toAlwaysKeep,
IEnumerable<string> toIgnore,
IEnumerable<string> namePrefixes,
IEnumerable<IYamlTypeConverter> customConverters,
bool allowReadOnly)
{
_innerTypeDescriptor = innerTypeDescriptor;
_toAlwaysKeep = new HashSet<string>(toAlwaysKeep);
_toIgnore = new HashSet<string>(toIgnore);
_namePrefixes = namePrefixes;
_allowReadOnly = allowReadOnly;
_customConverters = customConverters;
}

/// <inheritdoc />
Expand Down Expand Up @@ -558,7 +563,10 @@ public override IEnumerable<IPropertyDescriptor> GetProperties(Type type, object
var val = prop?.GetValue(container);
if (val != null && prop != null && !type.IsValueType
&& _namePrefixes.Any(prefix => prop.PropertyType.FullName!.StartsWith(prefix, StringComparison.InvariantCulture)))
&& _namePrefixes.Any(prefix => prop.PropertyType.FullName!.StartsWith(prefix, StringComparison.InvariantCulture))
// Any type covered by a custom converter shouldn't be passed through here. We don't know
// how those are serialized, it is likely not just by listing their properties.
&& _customConverters.All(conv => !conv.Accepts(prop.PropertyType)))
{
var pr = GetProperties(prop.PropertyType, val);
if (!pr.Any()) return false;
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.24.2
1.24.3

0 comments on commit 3d5765e

Please sign in to comment.