[kotlin-client] Add decodeOrNull helper for Jackson enums, fix decode KDoc#23823
Open
limoneren wants to merge 1 commit into
Open
[kotlin-client] Add decodeOrNull helper for Jackson enums, fix decode KDoc#23823limoneren wants to merge 1 commit into
limoneren wants to merge 1 commit into
Conversation
… KDoc (OpenAPITools#23791) Splits the two contracts that PR OpenAPITools#22535 (7.18.0) conflated: - decode() stays strict and Jackson-bound (@JsonCreator entry point) - decodeOrNull() is added as a lenient counterpart for direct callers that prefer the pre-7.19.0 null-on-unknown behavior This gives users impacted by the 7.19.0 change a trivial migration path (MyEnum.decode(x) -> MyEnum.decodeOrNull(x)) without giving up the Jackson safety fix or matching the kotlin-spring/Java client behavior. Also corrects the KDoc on decode() which still claimed "null otherwise" even though the function now throws.
Member
|
thanks for the PR if no further question/feedback, i'll merge it later this week |
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.
PR checklist
@JsonCreatorenums were affected (the two echo-api samples). All other generators produce identical output. No docs changed.master(upcoming7.x.0minor release - breaking changes with fallbacks).Summary
Follow-up to #22663 (which fixed the 7.18.0 silent-null regression in Jackson deserialization of Kotlin enums). Addresses concerns raised in #23791.
PR #22535 (7.18.0) tied two contracts together by adding
@JsonCreatorto the existingdecode()helper:decode()as a standalone function — historically nullable-returning, KDoc said "null otherwise."PR #22663 (7.19.0) restored the Jackson throwing behavior, but as a side effect changed
decode()'s direct-call contract for non-nullable enums (it now throws instead of returning null).This PR cleanly separates the two contracts by adding
decodeOrNull()alongsidedecode()in the Jackson branch:decode()— strict,@JsonCreatorentry point (unchanged from 7.19.0)decodeOrNull()— lenient helper for manual callers; always returns null on unknown values or null inputThis follows idiomatic Kotlin conventions (
toIntOrNull,firstOrNull, etc.) and gives anyone affected by the 7.19.0 change a trivial one-line migration:MyEnum.decode(x)→MyEnum.decodeOrNull(x).Also corrects the KDoc on
decode()which still claimed "null otherwise" even though the function now throws.Changes
modules/openapi-generator/src/main/resources/kotlin-client/enum_class.mustache: addsdecodeOrNull()in the Jackson branch; updates thedecode()KDoc so it no longer says "null otherwise" when the function may throw.KotlinClientCodegenModelTest.java: new unit testtestJacksonEnumsExposeDecodeOrNullHelperverifyingdecodeOrNullis generated and@JsonCreatoris still applied only todecode.kotlin-jvm-spring-3-restclientandkotlin-jvm-spring-3-webclientecho-api samples — the only samples containing Jackson-annotated Kotlin enums).Validation
Resolves #23791
Summary by cubic
Add decodeOrNull() to Kotlin Jackson enums to restore a lenient, null-returning lookup for manual calls, while keeping decode() as the strict @JsonCreator entry point. Also fixes decode() KDoc and adds a test; regenerated the affected echo-api Kotlin samples.
New Features
Bug Fixes
Written for commit ec18c9e. Summary will update on new commits. Review in cubic