zio-schema icon indicating copy to clipboard operation
zio-schema copied to clipboard

JSON codec built from auto-derived schema fails for enumeration with intermediate type

Open dubinsky opened this issue 11 months ago • 6 comments

//> using scala 3.4.0
//> using dep dev.zio::zio-schema:1.0.1
//> using dep dev.zio::zio-schema-derivation:1.0.1
//> using dep dev.zio::zio-schema-json:1.0.1

sealed trait Animal
object Animal:
  sealed trait Mammal extends Animal
  case object Bison extends Mammal
  given schema: zio.schema.Schema[Animal] = zio.schema.DeriveSchema.gen[Animal]
  given jsonCodec: zio.json.JsonCodec[Animal] = zio.schema.codec.JsonCodec.jsonCodec(schema)

  @main def main: String =
    import zio.json.EncoderOps
    val value: Animal = Bison
    // Exception in thread "main" java.lang.ClassCastException:
    //   class zio.schema.Schema$Enum1 cannot be cast to class zio.schema.Schema$CaseClass0
    value.toJson

dubinsky avatar Mar 11 '24 02:03 dubinsky

/bounty $75

jdegoes avatar Jun 08 '24 01:06 jdegoes

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #668 with your implementation plan
  2. Submit work: Create a pull request including /claim #668 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-schema!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🔴 @BijenderKumar1 Jun 25, 2024, 4:16:56 PM WIP
🟢 @pablf #706

algora-pbc[bot] avatar Jun 08 '24 01:06 algora-pbc[bot]

/attempt #668

Algora profile Completed bounties Tech Active attempts Options
@BijenderKumar1 1 ZIO bounty
Cancel attempt

BijenderKumar1 avatar Jun 25 '24 16:06 BijenderKumar1

💡 @pablf submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] avatar Jun 30 '24 19:06 algora-pbc[bot]

@BijenderKumar1: Reminder that in 7 days the bounty will become up for grabs, so please submit a pull request before then 🙏

algora-pbc[bot] avatar Jul 02 '24 16:07 algora-pbc[bot]

The bounty is up for grabs! Everyone is welcome to /attempt #668 🙌

algora-pbc[bot] avatar Jul 09 '24 16:07 algora-pbc[bot]