Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
- Type in expressions to have them evaluated.
- Type :help for more information.
- scala> import io.circe._
- import io.circe._
- scala> import io.circe.generic.auto._
- import io.circe.generic.auto._
- scala> import io.circe.jawn._
- import io.circe.jawn._
- scala> import io.circe.syntax._
- import io.circe.syntax._
- scala> case class User(id: Long, name: String, email: String)
- defined class User
- scala>
- scala> :paste
- // Entering paste mode (ctrl-D to finish)
- val json = """
- {
- "name": "Foo McBar",
- "email": "foo@mcbar.com"
- }
- """
- // Exiting paste mode, now interpreting.
- json: String =
- "
- {
- "name": "Foo McBar",
- "email": "foo@mcbar.com"
- }
- "
- scala> decode[Long => User](json)
- res5: cats.data.Xor[io.circe.Error,Long => User] = Right(<function1>)
- scala> res5.map { z => z(100) }
- res7: cats.data.Xor[io.circe.Error,User] = Right(User(100,Foo McBar,foo@mcbar.com))
- scala> res5.map { z => z(102) }
- res8: cats.data.Xor[io.circe.Error,User] = Right(User(102,Foo McBar,foo@mcbar.com))
- scala>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement