Fix #668: JSON codec built from auto-derived schema fails for enumerat#1050
Open
JoshKappler wants to merge 1 commit intozio:mainfrom
Open
Fix #668: JSON codec built from auto-derived schema fails for enumerat#1050JoshKappler wants to merge 1 commit intozio:mainfrom
JoshKappler wants to merge 1 commit intozio:mainfrom
Conversation
…s for enumeration with intermediate type
|
JoshKappler seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Author
|
This is an automated CLA (Contributor License Agreement) check from the CLA assistant bot, not a code review comment. It's asking you to sign the CLA before the contribution can be accepted. To resolve this:
This is a standard requirement for most open source projects — no code changes needed. Would you like me to help with anything else on this PR? |
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.
Summary
The JSON codec's
enumDecoderusedisInstanceOf[CaseClass0[_]]checks with unsafeasInstanceOfcasts to determine simple enum handling, which was misaligned with the encoder'ssimpleEnumannotation check. This caused aClassCastExceptionwhen an enumeration contained intermediate sealed traits (producingSchema.Enumschemas instead ofSchema.CaseClass0). The fix aligns the decoder with the encoder by using thesimpleEnumannotation check and replaces unsafe casts with the existing type-safeconstructEnumCasehelper.Changes
zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala: ChangedenumDecoderto check thesimpleEnumannotation (matchingenumEncoderbehavior) instead of checking whether all cases areCaseClass0instances. Replaced unsafeasInstanceOf[Schema.CaseClass0[...]]casts with calls to the existingconstructEnumCasehelper, which safely handles bothCaseClass0andSchema.Enumcases.Testing
JsonCodecSpec668with 10 test cases covering enumerations with intermediate types — all pass on Scala 2.13 and Scala 3.3.7.zioSchemaJsonJVM/testsuite passes (298 tests on Scala 2.13, 304 on Scala 3).zioSchemaDerivationJVM/testsuite passes (91 on Scala 2.13, 101 on Scala 3)./claim #668