Open jivanic-demystdata opened 1 month ago
Why are you trying to summon the decoder instead of deriving it? This compiles:
import zio.json.*
import Example.ValidationState
final case class Example[State <: ValidationState](a: String, b: Int) derives JsonDecoder
object Example {
type UnvalidatedExample = Example[ValidationState.Unvalidated]
type ValidatedExample = Example[ValidationState.Validated]
enum ValidationState {
case Unvalidated, Validated
}
object ValidationState {
type Unvalidated = Unvalidated.type
type Validated = Validated.type
}
given JsonDecoder[UnvalidatedExample] = DeriveJsonDecoder.gen[Example[?]].asInstanceOf[JsonDecoder[UnvalidatedExample]]
}
Never mind -- I missed that it's the deriving
bit you were asking about. Not sure why that doesn't work, as JsonDecoder.derived
just calls DeriveJsonDecoder.gen
.
I have this code:
which fails to compile with error: