Skip to content

fix: preserve array encoding serialization format for customized properties#10126

Merged
jorgerangel-msft merged 6 commits into
mainfrom
copilot/fix-serialization-format-properties
Mar 25, 2026
Merged

fix: preserve array encoding serialization format for customized properties#10126
jorgerangel-msft merged 6 commits into
mainfrom
copilot/fix-serialization-format-properties

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

When a property with @encode(ArrayEncoding.commaDelimited) is customized via [CodeGenMember], the encoding metadata is lost — the generated serialization code falls back to default array handling instead of using the delimiter-based encoding.

Root cause: Two gaps in how SerializationFormat flows to customized properties:

  • PropertyWireInformation(InputProperty) constructor only called TypeFactory.GetSerializationFormat(inputProperty.Type), which recurses into the element type and ignores InputModelProperty.Encode. The parallel logic in PropertyProvider.GetSerializationFormat() correctly checks for array encoding but PropertyWireInformation did not.
  • CreateWritePropertiesStatements and the deserialization path read property.SerializationFormat (a readonly field set only during PropertyProvider construction from spec). For customized properties constructed from user C# code, this is always Default.

Changes:

  • TypeFactory.cs — Add internal GetSerializationFormat(InputProperty) overload that checks InputModelProperty.Encode for array types before falling back to the existing GetSerializationFormat(InputType). This centralizes the property-level serialization format resolution in a single place.
  • PropertyWireInformation.cs — Call the new TypeFactory.GetSerializationFormat(inputProperty) overload directly, removing the previously duplicated static helper.
  • PropertyProvider.cs — Call the new TypeFactory.GetSerializationFormat(inputProperty) overload directly, removing the previously duplicated private method.
  • MrwSerializationTypeDefinition.cs — Use wireInfo.SerializationFormat consistently in both serialization (line 1757) and deserialization (line 1077) paths, matching all other call sites. This ensures customized properties pick up the format from WireInfo rather than the uninitialized PropertyProvider._serializationFormat.
  • Test — Add CanPreserveArrayEncodingForCustomizedProperty with TestData-based assertions validating that a [CodeGenMember]-renamed property with comma-delimited encoding produces the correct serialization output.

⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

…ay encoding

Fix PropertyWireInformation to handle array encoding metadata when
constructing from InputProperty, matching PropertyProvider behavior.
Also update MrwSerializationTypeDefinition to use WireInfo serialization
format consistently for both serialization and deserialization paths.

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/f951d06e-92e6-49f6-9690-c013979802ff
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Mar 24, 2026
Copilot AI changed the title [WIP] Fix serialization format for customized properties fix: preserve array encoding serialization format for customized properties Mar 24, 2026
Copilot AI requested a review from jorgerangel-msft March 24, 2026 21:05
…Property assertions

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/4406d355-b4f4-43e9-8a9c-d89f13693c48
Copilot AI and others added 2 commits March 24, 2026 22:21
…s internal method

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c7ba895c-8352-4294-8e3f-a0bc7242c583
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/c7ba895c-8352-4294-8e3f-a0bc7242c583
… methods

Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/caf19890-4278-4815-b032-aa61e5630356
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 24, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10126

commit: e388ae6

@jorgerangel-msft jorgerangel-msft marked this pull request as ready for review March 25, 2026 15:34
@jorgerangel-msft jorgerangel-msft added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit 7f43478 Mar 25, 2026
25 checks passed
@jorgerangel-msft jorgerangel-msft deleted the copilot/fix-serialization-format-properties branch March 25, 2026 22:29
msyyc pushed a commit that referenced this pull request Apr 1, 2026
…erties (#10126)

When a property with `@encode(ArrayEncoding.commaDelimited)` is
customized via `[CodeGenMember]`, the encoding metadata is lost — the
generated serialization code falls back to default array handling
instead of using the delimiter-based encoding.

**Root cause:** Two gaps in how `SerializationFormat` flows to
customized properties:

- `PropertyWireInformation(InputProperty)` constructor only called
`TypeFactory.GetSerializationFormat(inputProperty.Type)`, which recurses
into the element type and ignores `InputModelProperty.Encode`. The
parallel logic in `PropertyProvider.GetSerializationFormat()` correctly
checks for array encoding but `PropertyWireInformation` did not.
- `CreateWritePropertiesStatements` and the deserialization path read
`property.SerializationFormat` (a `readonly` field set only during
`PropertyProvider` construction from spec). For customized properties
constructed from user C# code, this is always `Default`.

**Changes:**

- **`TypeFactory.cs`** — Add `internal
GetSerializationFormat(InputProperty)` overload that checks
`InputModelProperty.Encode` for array types before falling back to the
existing `GetSerializationFormat(InputType)`. This centralizes the
property-level serialization format resolution in a single place.
- **`PropertyWireInformation.cs`** — Call the new
`TypeFactory.GetSerializationFormat(inputProperty)` overload directly,
removing the previously duplicated static helper.
- **`PropertyProvider.cs`** — Call the new
`TypeFactory.GetSerializationFormat(inputProperty)` overload directly,
removing the previously duplicated private method.
- **`MrwSerializationTypeDefinition.cs`** — Use
`wireInfo.SerializationFormat` consistently in both serialization (line
1757) and deserialization (line 1077) paths, matching all other call
sites. This ensures customized properties pick up the format from
`WireInfo` rather than the uninitialized
`PropertyProvider._serializationFormat`.
- **Test** — Add `CanPreserveArrayEncodingForCustomizedProperty` with
TestData-based assertions validating that a `[CodeGenMember]`-renamed
property with comma-delimited encoding produces the correct
serialization output.

<!-- START COPILOT CODING AGENT TIPS -->
---

⌨️ Start Copilot coding agent tasks without leaving your editor —
available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual
Studio](https://gh.io/cca-visual-studio-docs), [JetBrains
IDEs](https://gh.io/cca-jetbrains-docs) and
[Eclipse](https://gh.io/cca-eclipse-docs).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jorgerangel-msft <102122018+jorgerangel-msft@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants