Advertisement
Guest User

Untitled

a guest
May 26th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. package example
  2.  
  3. import io.circe._, io.circe.generic.auto._, io.circe.parser._, io.circe.syntax._
  4. import io.circe.optics.JsonPath._
  5.  
  6. object Hello extends App {
  7. val json = """
  8. {
  9. "iam" : {
  10. "teapot" : "Here is my snout"
  11. }
  12. }
  13. """
  14.  
  15. case class Iam(teapot: String)
  16.  
  17. val res = for {
  18. js <- parse(json)
  19. iam <- root.iam.as[Iam].
  20. getOption(js).toRight(ParsingFailure("iam field not specified", new Throwable))
  21. snout <- root.iam.teapot.string.
  22. getOption(js).toRight(ParsingFailure("couldnt get the teapot", new Throwable))
  23.  
  24. } yield snout -> iam
  25.  
  26. println(res)
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement