Adds support for Cron4s's CronExpr class to PureConfig.
In addition to core PureConfig, you'll need:
libraryDependencies += "com.github.pureconfig" %% "pureconfig-cron4s" % "0.17.4"
To load an CronExpr
into a configuration, create a class to hold it:
import cron4s.expr.CronExpr
import com.typesafe.config.ConfigFactory.parseString
import pureconfig._
import pureconfig.generic.auto._
import pureconfig.module.cron4s._
case class MyConfig(schedule: CronExpr)
We can read a MyConfig
with the following code:
val conf = parseString("""{ schedule: "10-35 2,4,6 * ? * *" }""")
// conf: com.typesafe.config.Config = Config(SimpleConfigObject({"schedule":"10-35 2,4,6 * ? * *"}))
ConfigSource.fromConfig(conf).load[MyConfig]
// res0: ConfigReader.Result[MyConfig] = Right(
// MyConfig(CronExpr(10-35, 2,4,6, *, ?, *, *))
// )