daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Aug 31st, 2015 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79).
  2. Type in expressions to have them evaluated.
  3. Type :help for more information.
  4.  
  5. scala> import io.circe._
  6. import io.circe._
  7.  
  8. scala> import io.circe.generic.auto._
  9. import io.circe.generic.auto._
  10.  
  11. scala> import io.circe.jawn._
  12. import io.circe.jawn._
  13.  
  14. scala> import io.circe.syntax._
  15. import io.circe.syntax._
  16.  
  17. scala> case class User(id: Long, name: String, email: String)
  18.  
  19. defined class User
  20.  
  21. scala>
  22. scala> :paste
  23. // Entering paste mode (ctrl-D to finish)
  24.  
  25. val json = """
  26.   {
  27.     "name": "Foo McBar",
  28.     "email": "foo@mcbar.com"
  29.   }
  30. """
  31.  
  32.  
  33. // Exiting paste mode, now interpreting.
  34.  
  35. json: String =
  36. "
  37.   {
  38.     "name": "Foo McBar",
  39.     "email": "foo@mcbar.com"
  40.   }
  41. "
  42.  
  43. scala> decode[Long => User](json)
  44. res5: cats.data.Xor[io.circe.Error,Long => User] = Right(<function1>)
  45.  
  46. scala> res5.map { z => z(100) }
  47. res7: cats.data.Xor[io.circe.Error,User] = Right(User(100,Foo McBar,foo@mcbar.com))
  48.  
  49. scala> res5.map { z => z(102) }
  50. res8: cats.data.Xor[io.circe.Error,User] = Right(User(102,Foo McBar,foo@mcbar.com))
  51.  
  52. scala>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top