Skip to content

feat(renderer): support Serde for large fixed-size arrays - #325

Merged
Bergmann89 merged 1 commit into
Bergmann89:masterfrom
sundermann:feat/serde-large-arrays
Nov 12, 2026
Merged

Bergmann89 merged 1 commit into
Bergmann89:masterfrom
sundermann:feat/serde-large-arrays

Conversation

@sundermann

@sundermann sundermann commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Serde derives do not support fixed-size arrays longer than 32 elements. This adds opt-in adapters to the Serde render steps while preserving their generated Rust field types.

Changes

  • Add large_arrays to RenderStep::TypesSerdeQuickXml and RenderStep::TypesSerdeXmlRs, disabled by default through the existing Serde configuration helpers.
  • Support named fields, newtypes, enum payloads, aliases, and nested containers using serde_with adapters. Preserve custom codecs and field defaults with shared boolean default metadata.
  • Keep plain Types and direct quick-xml generation free of automatic Serde attributes. No settings are added to RendererConfig, renderer MetaData, or the Renderer builder.
  • Add compiled fixtures, serialization tests, a regression for stray Serde attributes, and a 360-element array example. Backend limitations are documented in the example README.

Generated-code consumers enabling this option must depend on serde_with with its std or alloc feature. The generator gains no new production dependency.

Breaking changes: RenderStep::TypesSerdeQuickXml becomes a struct variant, and TypesSerdeXmlRs gains a required large_arrays field. Initialize it to false to preserve existing behavior. The concrete SerdeQuickXmlTypesRenderStep, SerdeXmlRsV7TypesRenderStep, and SerdeXmlRsV8TypesRenderStep also become structs with this field; callers can use ::default() for the previous behavior.

Checklist

  • Tests for the change (a bug fix has a test that fails without the fix)
  • Changed snapshots are regenerated with update-expectations and reviewed
  • cargo fmt, cargo clippy and cargo test pass (see CONTRIBUTING.md)
  • Breaking changes of the public API or the generated code are described above

@Bergmann89 Bergmann89 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, nice addition! The use case is real (minOccurs == maxOccurs > 32 plus Serde derives does not compile today), and I like that the default output is unchanged and there is no new production dependency.

The main point is where the option lives: serde_large_arrays does not belong into RendererConfig (or MetaData), it only affects the Serde render steps. Please make it an option of these steps, similar to RenderStep::QuickXmlDeserialize { boxed_deserializer, skip_unknown_elements }, e.g. RenderStep::TypesSerdeQuickXml { large_arrays: bool } and RenderStep::TypesSerdeXmlRs { version, large_arrays }. Then the plain Types step does not need the adapters at all, which also removes the problem that #[serde(...)] attributes are rendered without any Serde derive. Turning TypesSerdeQuickXml into a struct variant is a breaking change of the config, please mention it in the PR description.

The rest is smaller cleanup.

Comment thread xsd-parser/src/config/renderer.rs Resolved
Comment thread xsd-parser/src/config/mod.rs Resolved
Comment thread xsd-parser/Cargo.toml Resolved
Add an opt-in large_arrays setting to the Serde type render steps. Emit
serde_with adapters for arrays longer than 32 elements while preserving
field types, aliases, nested containers, custom codecs and defaults.

Keep configuration local to the Serde steps so plain Types and direct
quick-xml generation never receive automatic Serde attributes. Preserve
default generated output and add no production dependency. Represent
field default handling with a boolean and immutable override metadata.

Cover configured and direct steps, aliases, newtypes, payloads, optional
and boxed arrays, custom codecs and XML backend behavior with regression
tests and compiled fixtures. Include a 360-element example and document
backend limitations there.

BREAKING CHANGE: TypesSerdeQuickXml becomes a struct variant and
TypesSerdeXmlRs requires a large_arrays field. Set it to false for the
previous behavior. Concrete Serde type render steps also become structs;
their Default implementations preserve the previous behavior.
@sundermann
sundermann force-pushed the feat/serde-large-arrays branch from efc0b37 to ce2a9a2 Compare November 12, 2026 18:30
@sundermann

Copy link
Copy Markdown
Contributor Author

Thanks, for the guidance. I have updated the PR and your comments should be adressed now!

@Bergmann89
Bergmann89 merged commit 8599cc1 into Bergmann89:master Nov 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants