Created
April 21, 2015 22:28
-
-
Save trane/39fe8dac7096f309bd26 to your computer and use it in GitHub Desktop.
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 argonaut._ | |
import Argonaut._ | |
case class Session0(request: Int, data: Int) extends Session[Int, Int] | |
case class Session1(request: Int, data: String) extends Session[Int, String] | |
case class Session2(request: Int, data: Session0) extends Session[Int, Session0] | |
implicit def Session0CodecJson: CodecJson[Session0] = | |
casecodec2(Session0.apply, Session0.unapply)("request", "data") | |
implicit def Session1CodecJson: CodecJson[Session1] = | |
casecodec2(Session1.apply, Session1.unapply)("request", "data") | |
implicit def Session2CodecJson: CodecJson[Session2] = | |
casecodec2(Session2.apply, Session2.unapply)("request", "data") | |
def toJson[A <: Session[_,_] : argonaut.CodecJson](s: A): argonaut.Json = | |
implicitly[CodecJson[A]].encode(s) | |
scala> toJson(Session2(1, Session0(1, 1))) | |
res7: argonaut.Json = {"request":1,"data":{"request":1,"data":1}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment