Last active
October 17, 2017 23:22
-
-
Save NeQuissimus/06f7d1256c632b46a56dd57dfb48481e to your computer and use it in GitHub Desktop.
circe + refined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import $ivy.`io.circe::circe-generic:0.8.0` | |
import $ivy.`io.circe::circe-parser:0.8.0` | |
import $ivy.`io.circe::circe-refined:0.8.0` | |
import $ivy.`org.scalaz::scalaz-core:7.2.16` | |
import eu.timepit.refined._ | |
import eu.timepit.refined.api.Refined | |
import eu.timepit.refined.auto._ | |
import eu.timepit.refined.boolean._ | |
import eu.timepit.refined.collection._ | |
import eu.timepit.refined.generic._ | |
import io.circe._ | |
import io.circe.generic.auto._ | |
import io.circe.parser._ | |
import io.circe.refined._ | |
import io.circe.syntax._ | |
import scalaz._ | |
import Scalaz._ | |
object Test { | |
type ShortStringSpec = NonEmpty And MaxSize[W.`10`.T] | |
type ShortString = String Refined ShortStringSpec | |
} | |
implicit def toScalazEither[T](e: Either[Error, T]): Error \/ T = e.disjunction | |
import Test._ | |
case class Doc(i: Int, s: ShortString) | |
val str: ShortString = "lala" | |
val d = Doc(42, str) | |
val t = d.asJson.noSpaces | |
val good: Error \/ Doc = decode[Doc](t) | |
val bad: Error \/ Doc = decode[Doc]("""{"i":21,"s":"abcdefghijk"}""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment