Skip to content

Fixes #237 - support multi-dimensional arrays#238

Open
mlankamp wants to merge 1 commit intoAzureCosmosDB:mainfrom
mlankamp:issue-237
Open

Fixes #237 - support multi-dimensional arrays#238
mlankamp wants to merge 1 commit intoAzureCosmosDB:mainfrom
mlankamp:issue-237

Conversation

@mlankamp
Copy link
Copy Markdown

@mlankamp mlankamp commented Mar 15, 2026

Extended the WriteFieldValue function to support multi-dimensional arrays

Fixes #237

@mlankamp
Copy link
Copy Markdown
Author

@philnach & @markjbrown How do I request a review?

@philnach
Copy link
Copy Markdown
Collaborator

@mlankamp, thanks for submitting the PR and reaching out. you've done the right thing by opening a PR. You could in the Reviewers panel on the PR request specific people Requesting reviews from collaborators and organization members to review your code.

With that said, I'll take a look.

@philnach philnach requested review from Copilot and philnach March 30, 2026 18:29
Copy link
Copy Markdown
Collaborator

@philnach philnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tests for this scenario to ensure the behavior works? Tests would go into this file: https://github.com/AzureCosmosDB/data-migration-desktop-tool/blob/main/Interfaces/Cosmos.DataTransfer.Common.UnitTests/DataItemJsonConverterTests.cs

@mlankamp
Copy link
Copy Markdown
Author

Of course! Will add them tomorrow

@philnach philnach review requested due to automatic review settings March 30, 2026 18:46
}
else if (arrayItem is not string && arrayItem is IEnumerable childs)
{
WriteFieldValue(writer, "", childs, includeNullFields);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR — adding support for nested (multi-dimensional) arrays makes sense.

That said, I’m a bit concerned about the current approach of handling nested arrays by calling:

WriteFieldValue(writer, "", childs, includeNullFields);

relies on:

if (!string.IsNullOrWhiteSpace(propertyName.Value)) { writer.WriteStartArray(propertyName); }
else { writer.WriteStartArray(); }

Could we refactor nested-array writing so it doesn’t depend on passing fieldName == "" and the propertyName.Value check?

For example:

introduce a dedicated helper that writes an array value (no property name), e.g. WriteArrayValue(Utf8JsonWriter writer, IEnumerable items, ...)
use that helper for nested arrays so it always calls writer.WriteStartArray() / writer.WriteEndArray()

(Optional)
The nested-array detection (arrayItem is not string && arrayItem is IEnumerable) is very broad and may accidentally treat things like byte[] as arrays of numbers. It might be worth tightening this to the specific collection types we expect to see here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multi-dimensional arrays when writing json (example geojson polygon)

2 participants