Skip to content

fix(http-client-java): gate XML serializer to azure-v1 data-plane and skip raw bytes payloads - #11329

Merged
weidongxu-microsoft merged 4 commits into
microsoft:mainfrom
weidongxu-microsoft:weidongxu/fix-xml-serializer-bytes
Jul 22, 2026
Merged

fix(http-client-java): gate XML serializer to azure-v1 data-plane and skip raw bytes payloads#11329
weidongxu-microsoft merged 4 commits into
microsoft:mainfrom
weidongxu-microsoft:weidongxu/fix-xml-serializer-bytes

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Contributor

Fix XML serializer gating for byte[] payloads

Problem

A recent change (support XML serialization in the http-client-java generator) emitted a static XML ObjectSerializer SERIALIZER field whenever an operation had an XML content-type. This was wrong in two cases:

  1. Raw byte[]/BinaryData payloads (e.g. an operation returning a raw XML document as bytes, like azure-analytics-planetarycomputer's getWmtsCapabilities). Here the SERIALIZER referenced an XmlSerializerProviders helper that is only generated for models actually used in XML, so the generated code failed to compile.
  2. Non azure-v1 data-plane clients. XML ObjectSerializer handling only applies to the azure-core (v1) data-plane flavor.

Fix

  • Gate SERIALIZER emission on isAzureV1() && isDataPlaneClient().
  • Only use the XML ObjectSerializer when the payload is an actual model, i.e. not byte[]/BinaryData/Base64Url.
  • Inspect the convenience method's model body types (unwrapping Mono/Flux/Response/ResponseBase/PagedIterable/PagedFlux/PagedResponseBase) instead of the protocol method's BinaryData type.

Verification

  • New tsp/xml-bytes-verify.tsp case (data-plane azure-v1 op returning bytes with application/xml) generates committed source under tsptest/xmlbytesverify.
  • New reflection-based XmlBytesVerifyTests asserts the generated clients declare no static SERIALIZER field for raw bytes payloads, with a positive control on payload.xml.SimpleModelValueClient.
  • Regenerating payload/xml produces identical output (SERIALIZER count unchanged at 312), confirming real XML model clients are unaffected.

Ref: Azure/azure-sdk-for-java#49877

… skip raw bytes payloads

XML ObjectSerializer (SERIALIZER) was emitted whenever an operation had an XML
content-type, even for raw byte[]/BinaryData payloads and non-data-plane clients.
For raw XML bytes responses this referenced a non-generated XmlSerializerProviders
helper, causing a build break.

Gate SERIALIZER emission on isAzureV1() && isDataPlaneClient() and on the payload
being an actual model (not byte[]/BinaryData/Base64Url), inspecting the convenience
method model body types rather than the protocol method's BinaryData.

Adds a tsp/xml-bytes-verify.tsp verification case and a reflection-based
XmlBytesVerifyTests asserting no SERIALIZER field is generated for raw bytes payloads.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9caec63c-f4be-44fe-9f9c-4f2eda60ff60
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-java
Show changes

@typespec/http-client-java - fix ✏️

Fix XML serialization to only apply for azure-v1 data-plane clients, and to skip the XML ObjectSerializer for raw byte[]/BinaryData payloads that are not structured XML models. This avoids emitting a reference to a non-generated XmlSerializerProviders helper (which caused a build break) for operations that return raw XML bytes.

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 21, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

weidongxu-microsoft and others added 3 commits July 22, 2026 00:51
Rename the generated static XML ObjectSerializer field from SERIALIZER to
XML_SERIALIZER for clarity and regenerate the java test baselines.

Includes full Generate.ps1 regeneration updates for payload/xml and updates
reflection assertions in XmlBytesVerifyTests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9caec63c-f4be-44fe-9f9c-4f2eda60ff60
…apping

Remove duplicated response-body unwrapping logic from sync/async convenience
templates and reuse ConvenienceMethodTemplateBase#getConvenienceResponseBodyType.

Keep sync-specific ResponseBase detection helper for response construction only.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9caec63c-f4be-44fe-9f9c-4f2eda60ff60
…wrapping

Add unit tests for ConvenienceMethodTemplateBase#getConvenienceResponseBodyType
covering mono/response, paged flux, response base, nested paged response base,
and non-generic passthrough cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 9caec63c-f4be-44fe-9f9c-4f2eda60ff60
@weidongxu-microsoft
weidongxu-microsoft marked this pull request as ready for review July 22, 2026 00:29
@weidongxu-microsoft

Copy link
Copy Markdown
Contributor Author

@weidongxu-microsoft
weidongxu-microsoft added this pull request to the merge queue Jul 22, 2026
Merged via the queue into microsoft:main with commit 43ff004 Jul 22, 2026
35 checks passed
@weidongxu-microsoft
weidongxu-microsoft deleted the weidongxu/fix-xml-serializer-bytes branch July 22, 2026 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants