Skip to content

Commit 875df3a

Browse files
committed
Fix JsonElement serialization error for ControlPropertyState in dynamic properties.
Add app with categoty and ControlPropertyState to test (RoundripTests)
1 parent 94744e5 commit 875df3a

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎src/PAModel/IR/IRStateHelpers.cs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private static (Item item, int index) CombineIRAndState(BlockNode blockNode, Err
360360
foreach (var propIR in blockNode.Properties)
361361
{
362362
// Dynamic properties could be null for the galleryTemplateTemplate
363-
var isDynamicProperty = state.DynamicProperties != null &&
363+
var isDynamicProperty = state.DynamicProperties != null &&
364364
((isInResponsiveLayout && DynamicProperties.IsResponsiveLayoutProperty(propIR.Identifier)) ||
365365
// Check if property is dynamic (responsive layout or has metadata like ControlPropertyState)
366366
state.DynamicProperties.Any(dp => dp.PropertyName == propIR.Identifier));
@@ -380,7 +380,15 @@ private static (Item item, int index) CombineIRAndState(BlockNode blockNode, Err
380380
// Add dummy dynamic output props in the state at the end
381381
foreach (var dynPropState in state.DynamicProperties.Where(propState => propState.Property == null))
382382
{
383-
dynamicProperties.Add(new DynamicPropertyJson() { PropertyName = dynPropState.PropertyName });
383+
var dummyProp = new DynamicPropertyJson() { PropertyName = dynPropState.PropertyName };
384+
385+
// Preserve ControlPropertyState if it exists
386+
if (dynPropState.ControlPropertyState != null)
387+
{
388+
dummyProp.ControlPropertyState = JsonSerializer.SerializeToElement(dynPropState.ControlPropertyState);
389+
}
390+
391+
dynamicProperties.Add(dummyProp);
384392
}
385393

386394
// Reorder to preserve roundtripping
@@ -659,7 +667,7 @@ private static DynamicPropertyJson GetDynamicPropertyEntry(ControlState state, s
659667
{
660668
property.Rule = new RuleEntry()
661669
{
662-
InvariantScript = expression,
670+
InvariantScript = expression,
663671
RuleProviderType = "Unknown"
664672
};
665673
}

‎src/PAModel/Schemas/adhoc/Control.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class RuleEntry
2323
public string RuleProviderType { get; set; } // = "Unknown";
2424

2525
public string Category { get; set; }
26-
26+
2727
[JsonExtensionData]
2828
public Dictionary<string, JsonElement> ExtensionData { get; set; }
2929

@@ -109,7 +109,7 @@ public class DynamicPropertyJson
109109
public RuleEntry Rule { get; set; }
110110

111111
// object with additional properties
112-
public JsonElement ControlPropertyState { get; set; }
112+
public JsonElement? ControlPropertyState { get; set; }
113113

114114
[JsonExtensionData]
115115
public Dictionary<string, object> ExtensionData { get; set; }
Binary file not shown.

0 commit comments

Comments
 (0)