fix: preserve array encoding serialization format for customized properties#10126
Merged
jorgerangel-msft merged 6 commits intoMar 25, 2026
Merged
Conversation
…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
Copilot
AI
changed the title
[WIP] Fix serialization format for customized properties
fix: preserve array encoding serialization format for customized properties
Mar 24, 2026
…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
…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
commit: |
JoshLove-msft
approved these changes
Mar 25, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SerializationFormatflows to customized properties:PropertyWireInformation(InputProperty)constructor only calledTypeFactory.GetSerializationFormat(inputProperty.Type), which recurses into the element type and ignoresInputModelProperty.Encode. The parallel logic inPropertyProvider.GetSerializationFormat()correctly checks for array encoding butPropertyWireInformationdid not.CreateWritePropertiesStatementsand the deserialization path readproperty.SerializationFormat(areadonlyfield set only duringPropertyProviderconstruction from spec). For customized properties constructed from user C# code, this is alwaysDefault.Changes:
TypeFactory.cs— Addinternal GetSerializationFormat(InputProperty)overload that checksInputModelProperty.Encodefor array types before falling back to the existingGetSerializationFormat(InputType). This centralizes the property-level serialization format resolution in a single place.PropertyWireInformation.cs— Call the newTypeFactory.GetSerializationFormat(inputProperty)overload directly, removing the previously duplicated static helper.PropertyProvider.cs— Call the newTypeFactory.GetSerializationFormat(inputProperty)overload directly, removing the previously duplicated private method.MrwSerializationTypeDefinition.cs— UsewireInfo.SerializationFormatconsistently in both serialization (line 1757) and deserialization (line 1077) paths, matching all other call sites. This ensures customized properties pick up the format fromWireInforather than the uninitializedPropertyProvider._serializationFormat.CanPreserveArrayEncodingForCustomizedPropertywith 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.