[http-client-csharp] Initialize omitted required collections during deserialization - #12090
Jorge Rangel (jorgerangel-msft) with Copilot wants to merge 11 commits into
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
commit: |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
The required Cop static-analysis validation remains incomplete.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes C# model deserialization so omitted required, non-nullable collections initialize empty and remain serializable.
Changes:
- Adds collection fallbacks when invoking serialization constructors.
- Regenerates affected JSON/XML model output.
- Adds regression coverage for mutation, round-tripping, and explicit null rejection.
| File | Description |
|---|---|
MrwSerializationTypeDefinition.cs |
Adds required non-nullable collection fallback. |
RoundTripModelTests.cs |
Adds runtime regression tests. |
DeserializeArrayProperties.cs |
Updates array baseline. |
DeserializeDictionaryProperties.cs |
Updates dictionary baseline. |
XmlDeserializationMethodHandlesUnwrappedListProperty.cs |
Updates unwrapped XML baseline. |
XmlDeserializationMethodHandlesWrappedListProperty.cs |
Updates wrapped XML baseline. |
DynamicModel.Serialization.cs |
Regenerates collection fallbacks. |
ListWithContinuationTokenHeaderResponseResult.Serialization.cs |
Regenerates paging collection fallback. |
ListWithContinuationTokenResult.Serialization.cs |
Regenerates paging collection fallback. |
ListWithNextLinkResult.Serialization.cs |
Regenerates paging collection fallback. |
ListWithStringNextLinkResult.Serialization.cs |
Regenerates paging collection fallback. |
PageThing.Serialization.cs |
Regenerates page-item fallback. |
RoundTripModel.Serialization.cs |
Regenerates required collection fallbacks. |
XmlAdvancedModel.Serialization.cs |
Regenerates XML collection fallbacks. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
| private const string IsDefinedMethodName = "IsDefined"; | ||
| private const string IsCollectionDefinedMethodName = "IsCollectionDefined"; | ||
|
|
||
| public static ScopedApi<bool> IsCollectionDefined(ValueExpression collection) |
There was a problem hiding this comment.
Copilot this is a breaking change. Revert the modifier to public and just add a new internal overload
There was a problem hiding this comment.
Restored the public one-argument overload and kept the type-aware overload internal in 8d9e49a6. The targeted C# tests, generator build, and Cop checks pass.
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
| : IsCollectionDefined(collection); | ||
| } | ||
|
|
||
| public static bool IsConcreteCollection(CSharpType type) |
There was a problem hiding this comment.
Copilot if this is only used in this type, lets make it private. If it's needed elsewhere in the assembly, make this internal
There was a problem hiding this comment.
IsConcreteCollection is also used by MrwSerializationTypeDefinition, so I changed it to internal rather than private in 532e7bf4. The generator build, 409 targeted tests, and Cop checks pass.
…assembly Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>

Deserialization accepts JSON that omits required, non-nullable collections but leaves them null. Accessing those collections or immediately serializing the returned model can then throw
NullReferenceException.List<T>customizations. Preserve optional and required-nullable handling, populated/empty collections, and explicit-null rejection.J/Wserialization without prior getter access, and concrete-list customization cases. Update affected generated output and baselines.