Skip to content

Rule Parameter is inferring first element type to later elements in expandoObject list #704

@kudimimohan

Description

@kudimimohan

I’m sending JSON data converted to an ExpandoObject, as I don’t have the flexibility to use strongly typed inputs.

The JSON includes both objects and arrays, where the array elements contain nested properties.
In C#, the corresponding type is List<Dictionary<string, object>>.

However, when this data is passed to the rule engine, I’m observing data loss in nested properties for subsequent array elements.

{ "records": [ { "Product1": { "isAvailable": false, "details": { "type": "electronic", "sku": "123" } }, "product2": { "isAvailable": false, "details": { "type": "cosmetic", "sku": "566" } } }, { "Product1": { "isAvailable": false, "details": { "type": "electronic", "sku": "45" } }, "product2": { "isAvailable": false, "details": { "type": "cosmetic", "sku": "78", "loc": "TR", "units": "7" } } } ], "data": {} }

var expandoInput = JsonConvert.DeserializeObject<ExpandoObject>( inputJson, new ExpandoObjectConverter() )!;
or

var input = new RuleParameter("input", inputJson);

Behavior Observed

When I send the ExpandoObject to the rule engine and access it in a helper method, I notice that nested properties that are not present in the first array element are missing in subsequent elements.

Specifically, in the above example, the second record’s product2.details does not include loc and units, as they were not present in the first record’s product2.details.

Analysis

After investigation, it seems that:

Utils.CreateAbstractClassType infers the CLR element type for a list only from the first list element.

As a result, the dynamically generated CLR type only includes properties present in the first element.

Any properties that exist only in later elements are excluded during type creation and subsequently ignored by CreateObject, leading to data loss.

{ "name": "result", "expression": "Helpers.DoSomething(input.rows)" }

public static bool DoSomething(object rows) { // Process rows }

Questions

Is my understanding of this issue correct?

If so, is this a known limitation or a tracked issue?

Are there any current workarounds or planned fixes to handle dynamically varying JSON structures within arrays?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions