Skip to content

Commit

Permalink
Merge pull request #1092 from hypar-io/fix-representations-serialization
Browse files Browse the repository at this point in the history
Fix: missing column edges by correcting MergeSubResult handling for SharedObjects
  • Loading branch information
katehryhorenko authored Feb 5, 2025
2 parents a379d25 + 7380b6a commit e26e2c3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Elements/src/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void MergeSubResult(GatherSubElementsResult gatherResult, bool hasJsonIgn
{
if (isTypeRelatedToSharedObjects)
{
ElementsFromSharedObjectProperties.AddRange(gatherResult.ElementsFromSharedObjectProperties);
ElementsFromSharedObjectProperties.AddRange(gatherResult.Elements);
}
else
{
Expand Down Expand Up @@ -508,10 +508,10 @@ private GatherSubElementsResult RecursiveGatherSubElements(object obj)
// A dictionary created for the purpose of caching properties
// that we need to recurse, for types that we've seen before.
var props = new Dictionary<Type, List<PropertyInfo>>();
return RecursiveGatherSubElementsInternal(obj, props);
return RecursiveGatherSubElementsInternal(obj, props, false);
}

private GatherSubElementsResult RecursiveGatherSubElementsInternal(object obj, Dictionary<Type, List<PropertyInfo>> properties)
private GatherSubElementsResult RecursiveGatherSubElementsInternal(object obj, Dictionary<Type, List<PropertyInfo>> properties, bool parentHasJsonIgnore)
{
GatherSubElementsResult result = new GatherSubElementsResult();

Expand Down Expand Up @@ -585,13 +585,13 @@ private GatherSubElementsResult RecursiveGatherSubElementsInternal(object obj, D
}

// Do not save shared object to the model if it is marked with JsonIgnore (e.g. ElementRepresentation)
bool hasJsonIgnore = p.GetCustomAttributes(typeof(JsonIgnoreAttribute), true).Any();
bool hasJsonIgnore = parentHasJsonIgnore || p.GetCustomAttributes(typeof(JsonIgnoreAttribute), true).Any();

if (pValue is IList elems)
{
foreach (var item in elems)
{
var subElements = RecursiveGatherSubElementsInternal(item, properties);
var subElements = RecursiveGatherSubElementsInternal(item, properties, hasJsonIgnore);
result.MergeSubResult(subElements, hasJsonIgnore, isTypeRelatedToSharedObjects);
}
continue;
Expand All @@ -602,13 +602,13 @@ private GatherSubElementsResult RecursiveGatherSubElementsInternal(object obj, D
{
foreach (var value in dict.Values)
{
var subElements = RecursiveGatherSubElementsInternal(value, properties);
var subElements = RecursiveGatherSubElementsInternal(value, properties, hasJsonIgnore);
result.MergeSubResult(subElements, hasJsonIgnore, isTypeRelatedToSharedObjects);
}
continue;
}

var gatheredSubElements = RecursiveGatherSubElementsInternal(pValue, properties);
var gatheredSubElements = RecursiveGatherSubElementsInternal(pValue, properties, hasJsonIgnore);
result.MergeSubResult(gatheredSubElements, hasJsonIgnore, isTypeRelatedToSharedObjects);
}
catch (Exception ex)
Expand Down

0 comments on commit e26e2c3

Please sign in to comment.