The circe
extension adds the possibility of using CronExpr
in JSON messages. To use it
just add the following to your dependencies:
libraryDependencies ++= Seq(
"com.github.alonsodomin.cron4s" %% "cron4s-circe" % "0.6.1",
"io.circe" %% "circe-core" % "0.13.0
)
And add the correct import:
import cron4s._
import cron4s.circe._
import io.circe._
import io.circe.syntax._
This should be enough to be able to encode and decode cron expressions as JSON with Circe:
val cron = Cron.unsafeParse("10-35 2,4,6 * ? * *")
// cron: CronExpr = CronExpr(10-35, 2,4,6, *, ?, *, *)
val jsonCron = cron.asJson
// jsonCron: Json = JString("10-35 2,4,6 * ? * *")
jsonCron.as[CronExpr]
// res0: Decoder.Result[CronExpr] = Right(CronExpr(10-35, 2,4,6, *, ?, *, *))