Last active
November 2, 2016 17:52
-
-
Save atamborrino/2c397ac9df5ebefe71d168530d03e37d to your computer and use it in GitHub Desktop.
Play Json vs Circe simple validation with error accumulation and no auto-derivation
This file contains hidden or 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
case class Data(s: String, i: Int) | |
object Circe { | |
import io.circe._ | |
import cats.implicits._ | |
implicit val decoder: AccumulatingDecoder[Data] = ( | |
Decoder[String].prepare(_.downField("s")) |@| | |
Decoder[Int].prepare(_.downField("i")) | |
).map(Data.apply) | |
.accumulating | |
} | |
object PlayJson { | |
import play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
implicit val reads: Reads[Data] = ( | |
(__ \ "s").read[String] ~ | |
(__ \ "i").read[Int] | |
)(Data.apply _) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment