Skip to content

Instantly share code, notes, and snippets.

@andyscott
Created January 6, 2017 09:17
Show Gist options
  • Save andyscott/d29f7d36fd6e58d499e03f963ea94e22 to your computer and use it in GitHub Desktop.
Save andyscott/d29f7d36fd6e58d499e03f963ea94e22 to your computer and use it in GitHub Desktop.
import com.typesafe.config.Config
import classy.core.Decoder
import classy.generic.derive._
import classy.config._
case class Bar(value: String)
case class Foo(
a: String,
b: Option[Int],
c: List[String],
bars: List[Bar]
)
val decoder: Decoder[String, Foo] =
MkDecoder[Config, Foo]
.renameFields(_.toUpperCase)
.decoder.fromString
val res = decoder.decode("""
A = OKAY
B = 1235
C = [ZZZ]
BARS = [{ VALUE: hi }]
""")
// res: Right(Foo(OKAY,Some(1235),List(ZZZ),List(Bar(hi))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment