Tupson integrates with the awesome Typesafe config library.
You can rely on all Tupson's features like ADTs, enums, etc.
Quickest way to start playing with Tupson Config is with this Scastie example.
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"ba.sake::tupson-config:0.11.0"
)
def scalacOptions = super.scalacOptions() ++ Seq("-Yretain-trees")
libraryDependencies ++= Seq(
"ba.sake" %% "tupson-config" % "0.11.0"
)
scalacOptions ++= Seq("-Yretain-trees")
//> using dep ba.sake::tupson-config:0.11.0
Real-world example in sharaf-petclinic
Then, you can call .parseConfig[MyConf]
function on a Config
to parse it to the desired type:
import java.net.URL
import com.typesafe.config.ConfigFactory
import ba.sake.tupson.{given, *}
import ba.sake.tupson.config.*
case class MyConf(
port: Int,
url: URL,
string: String,
seq: Seq[String]
) derives JsonRW
val rawConfig = ConfigFactory.parseString("""
port = 7777
url = "http://example.com"
string = "str"
seq = [a, "b", c]
""")
val myConf = rawConfig.parseConfig[MyConf]
// MyConf(7777,http://example.com,str,List(a, b, c))