Skip to content

Support XML serialization in http-client-java generator#11305

Merged
weidongxu-microsoft merged 12 commits into
microsoft:mainfrom
weidongxu-microsoft:http-client-java_dpg-xml
Jul 21, 2026
Merged

Support XML serialization in http-client-java generator#11305
weidongxu-microsoft merged 12 commits into
microsoft:mainfrom
weidongxu-microsoft:http-client-java_dpg-xml

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Contributor

Summary

Adds XML serialization support to the @typespec/http-client-java generator (azure-core v1 flavor).

When any model is serialized/deserialized as XML, the generator now:

  1. Emits two helper classes into the implementation package — XmlSerializer (an ObjectSerializer backed by azure-xml + reflective fromXml(XmlReader)) and XmlSerializerProviders (factory). Emission is gated on isAzureV1() and any generating model with ClientModel::isUsedInXml.
  2. Uses the XML serializer overload in generated convenience methods — a static SERIALIZER field is declared on sync/async convenience clients, and BinaryData.fromObject(input, SERIALIZER) / toObject(X.class, SERIALIZER) are emitted when the request/response content type is XML.

The azure-v2 / clientcore flavor handles XmlSerializable natively and is unaffected. Non-XML output is unchanged.

Changes

  • Generator core: new resource templates XmlSerializer.java / XmlSerializerProviders.java; XML-aware SupportedMimeType handling in ConvenienceMethodTemplateBase, ConvenienceSyncMethodTemplate, ConvenienceAsyncMethodTemplate; static SERIALIZER field in ServiceSyncClientTemplate / ServiceAsyncClientTemplate; constants in ClientModelUtil.
  • Generator plugin: TypeSpecPlugin.writeHelperClasses emits the two helper files for XML models.
  • Test module: enabled the payload/xml spec, regenerated clients, and ported the XML test suite.

Testing

  • payload.xml.XmlTests: 26 run, 0 failures, 2 skipped (namespace scenarios).
  • Verified end-to-end: generator rebuild → emitter pack → tsp compile → generated output adopted into src matches, tests green.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
Add XmlSerializer/XmlSerializerProviders in the implementation package and route the toObject/fromObject convenience methods through the XML serializer overload so XML clients serialize XML instead of JSON. Add jackson-dataformat-xml for error-body decoding.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
… models

Emit XmlSerializer and XmlSerializerProviders implementation classes from the generator when any generating model is used in XML (azure-v1 flavor).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
…enience methods

Convenience method templates now declare a static XML ObjectSerializer and use the toObject/fromObject(serializer) overloads when the request/response content type is XML (azure-core v1 flavor).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
@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 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-java
Show changes

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

Support XML serialization for models: generate XmlSerializer helper classes and use the XML ObjectSerializer overload of toObject/fromObject in convenience methods for XML request/response bodies.

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 20, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

…t-java

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
weidongxu-microsoft and others added 3 commits July 20, 2026 13:23
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
…nt template

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7
@weidongxu-microsoft
weidongxu-microsoft force-pushed the http-client-java_dpg-xml branch from 128b933 to 733e444 Compare July 20, 2026 05:49
@weidongxu-microsoft

Copy link
Copy Markdown
Contributor Author

fix #11306

@weidongxu-microsoft
weidongxu-microsoft marked this pull request as ready for review July 20, 2026 06:23
… files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: a10e9989-905e-4380-a221-01c04f4da1f7

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@XiaofeiCao XiaofeiCao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't dive deep into the codegen. Generated models looks good.

@weidongxu-microsoft
weidongxu-microsoft added this pull request to the merge queue Jul 21, 2026
Merged via the queue into microsoft:main with commit d012e83 Jul 21, 2026
43 checks passed
@weidongxu-microsoft
weidongxu-microsoft deleted the http-client-java_dpg-xml branch July 21, 2026 04:28
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 21, 2026
- Update core-commit.json to microsoft/typespec d012e83 (XML serialization, microsoft/typespec#11305).
- Sync emitter test src/tsp via SyncTests.ps1.
- Generate.ps1: skip payload/xml via the generateScript filter (early return, matching core's skip pattern) instead of Remove-Item on the specs folder.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 21, 2026
- Update core-commit.json to microsoft/typespec d012e83 (XML serialization, microsoft/typespec#11305).
- Sync emitter test src/tsp via SyncTests.ps1 (adds payload/xml XmlTests).
- Generate.ps1: stop removing the payload/xml specs folder so xml is generated, matching core (which no longer skips xml).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 21, 2026
## Summary

- Update `packages/typespec-java/core-commit.json` to microsoft/typespec
[d012e83](microsoft/typespec@d012e83)
(Support XML serialization in http-client-java generator,
microsoft/typespec#11305).
- Sync emitter test `src`/`tsp` from core via `SyncTests.ps1` (adds
`emitter-tests/src/test/java/payload/xml` XmlTests).
- `emitter-tests/Generate.ps1`: stop removing `payload/xml` specs now
that the emitter supports XML models.
- Add chronus changelog entry (fix) mirroring the upstream XML
serialization change.

---------

Co-authored-by: Copilot <223556219+Copilot@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:java Issue for the Java client emitter: @typespec/http-client-java eng

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants