Last active
January 3, 2016 04:09
-
-
Save benkolera/8407051 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._, Argonaut._ | |
case class Message ( id:String , event:String, data:Json ) | |
object Message { | |
implicit val messageCodec = casecodec3( Message.apply , Message.unapply )( "id" , "event" , "data" ) | |
//scala> """{"id":"foo","event":"bar","data":"string"}""".decodeOption[Message] | |
//res1: Option[Message] = Some(Message(foo,bar,"string")) | |
//scala> """{"id":"foo","event":"bar","data":{"sub":"string"}}""".decodeOption[Message] | |
//res2: Option[Message] = Some(Message(foo,bar,{"sub":"string"})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment