zio / zio-schema

Compositional, type-safe schema definitions, which enable auto-derivation of codecs and migrations.
https://zio.dev/zio-schema
Apache License 2.0
141 stars 161 forks source link

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

Open dubinsky opened 6 months ago

dubinsky commented 6 months ago
//> 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
jdegoes commented 3 months ago

/bounty $75

algora-pbc[bot] commented 3 months ago

💎 $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
BijenderKumar1 commented 3 months ago

/attempt #668

Algora profile Completed bounties Tech Active attempts Options
@BijenderKumar1 1 ZIO bounty
Cancel attempt
algora-pbc[bot] commented 3 months ago

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

algora-pbc[bot] commented 3 months ago

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

algora-pbc[bot] commented 2 months ago

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