Skip to content

v4.0.0-RC14

Compare
Choose a tag to compare
@afsalthaj afsalthaj released this 23 Mar 05:20
· 47 commits to series/4.x since this release
c5e3fc2

Updates

  • Add type-discriminator support for scala-3 auto derivation. Note that this support already existed in scala-2 auto derivation
import zio.config._, magnolia._, typesafe._

@nameWithLabel("type")
sealed trait FooBar

case class Foo(name: String) extends FooBar
case class Bar() extends FooBar

case class MyConfig(a: FooBar, b: FooBar)

val hocon = 
 s"""
   {
     a : {
       type : Foo
       name : baz
     },

     # Bar is just name since it has no fields, and therefore no need of type descriminator 
     b : Bar
   }

 """

ConfigProvder.fromHoconString(hocon).load(deriveConfig[MyConfig])

Find more examples here:

https://github.com/zio/zio-config/tree/series/4.x/magnolia/shared/src/main/scala-dotty/zio/config/magnolia/examples

https://github.com/zio/zio-config/blob/series/4.x/examples/shared/src/main/scala/zio/config/examples/autoderivation/AutoDerivationPureConfig.scala