zio-config
zio-config copied to clipboard
no way to derive a string descriptor for sealed trait/case object "enum"
A typical representation of enums (in Scala 2) is the following:
sealed trait Status
case object Succeeded extends Status
case object Failed extends Status
case object Unknown extends Status
case class State(status: Status, a: String)
Currently, with the magnolia auto-derivation, this have the following representation (using JSON syntax for simplicity):
{
"status": {
"Unknown": {}
},
"a": "foobar"
}
There needs to be a way to derive the descriptor such that the Status
enum can be represented by a string.
I am not sure about this behaviour
The following works for me:
import zio.config._, typesafe._, magnolia._
import zio._
import zio.Console._
object MyApp extends ZIOAppDefault {
sealed trait Status
case object Succeeded extends Status
case object Failed extends Status
case object Unknown extends Status
case class State(status: Status, a: String)
val str =
s"""
"status" : "Unknown",
"a" : "foo"
"""
val myAppLogic = {
for {
str <- read(descriptor[State] from ConfigSource.fromHoconString(str))
_ <- ZIO.succeed(println(str))
} yield ()
}
def run = myAppLogic
}
Try this in scastie, and see how it goes: https://scastie.scala-lang.org/afsalthaj/JjQZyUNHQSar9OCQN2VJzQ/1