Skip to content

Preserve deserialization compatibility with older external enums - #1474

Merged
mtdowling merged 2 commits into
smithy-lang:mainfrom
timocov:fix-enum-deser-compat
Nov 30, 2026
Merged

mtdowling merged 2 commits into
smithy-lang:mainfrom
timocov:fix-enum-deser-compat

Conversation

@timocov

@timocov timocov commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

What behavior changes?

Generated deserializers now use the enum builder API for external enum and intEnum shapes. This lets newly generated code deserialize values using enum classes generated by Smithy Java 1.8.0. Enums generated in the same run still use the direct fromValue call.

Why is this change needed?

Smithy Java 1.9.0 started generating calls to fromValue for enum deserialization. Enum classes generated by 1.8.0 lack that method, so upgrading codegen for one module could cause a cannot find symbol error when it referenced enums from a separately generated module.

How was this validated?

  • Added regression coverage for string and integer enum members in an error structure, covering both external and locally generated enums
  • Reproduced the compile failure using the published 1.8.0 and 1.9.0 generators. With the patch, the generated error compiled against the original 1.8.0 enum classes and deserialized both known and unknown values.

What should reviewers focus on?

Symbols marked EXTERNAL_TYPE use builder().deserializeMember(...).build(), and local symbols use fromValue. DeserializerGeneratorTest covers both paths.

Ideally it would be good to detect which version of smithy-java was used to generate the enum and then make a decision, but I'm not sure if we have this information during the codegen time?

Additional Links


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

timocov and others added 2 commits November 30, 2026 11:09
Reword the external-enum comment so the builder path reads as the stable
cross-version contract rather than temporary 1.8.0 compatibility, document
why EnumGenerator must keep emitting builder(), and rename the test to
reflect that the behavior is not specific to errors.

@mtdowling mtdowling 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.

Thanks! I pushed a small follow-up commit that clarifies the comment (builder() is the stable cross-version contract for enums), notes in EnumGenerator why the builder must stay, and renames the test.

@mtdowling
mtdowling merged commit 0bed015 into smithy-lang:main Nov 30, 2026
7 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