Skip to main content
Version: 2.x

Refined Interop

Installation​

libraryDependencies ++= Seq(
"dev.zio" % "zio-json-interop-refined" % "0.7.3"
)

Usage​

import zio.json._
import zio.json.interop.refined._

import eu.timepit.refined.api.Refined
import eu.timepit.refined.collection.NonEmpty

case class Person(name: String Refined NonEmpty)

object Person {
implicit val decoder: JsonDecoder[Person] = DeriveJsonDecoder.gen
}
"""{ "name": "" }""".fromJson[Person]
// res0: Either[String, Person] = Left(
// value = ".name(Predicate isEmpty() did not fail.)"
// )
"""{ "name": "Aurora" }""".fromJson[Person]
// res1: Either[String, Person] = Right(value = Person(name = Aurora))