Fixes #237 - support multi-dimensional arrays#238
Fixes #237 - support multi-dimensional arrays#238mlankamp wants to merge 1 commit intoAzureCosmosDB:mainfrom
Conversation
|
@philnach & @markjbrown How do I request a review? |
|
@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
left a comment
There was a problem hiding this comment.
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
|
Of course! Will add them tomorrow |
| } | ||
| else if (arrayItem is not string && arrayItem is IEnumerable childs) | ||
| { | ||
| WriteFieldValue(writer, "", childs, includeNullFields); |
There was a problem hiding this comment.
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.
Extended the
WriteFieldValuefunction to support multi-dimensional arraysFixes #237