Created
November 7, 2014 15:35
-
-
Save tixxit/380af8de0f2471b368df to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package example | |
import argonaut._ | |
import Argonaut._ | |
sealed trait WidgetType | |
object WidgetType { | |
case object Sprocket extends WidgetType | |
case object Cog extends WidgetType | |
case object Doowazzle extends WidgetType | |
} | |
object json { | |
implicit val WidgetTypeCodec: CodecJson[WidgetType] = { | |
import WidgetType._ | |
CodecJson({ | |
case Sprocket => "sprocket".asJson | |
case Cog => "cog".asJson | |
case Doowazzle => "doowazzle".asJson | |
}, | |
{ j => | |
j.as[String].flatMap { | |
case "sprocket" => DecodeResult.ok(Sprocket) | |
case "cog" => DecodeResult.ok(Cog) | |
case "doowazzle" => DecodeResult.ok(Doowazzle) | |
case _ => DecodeResult.fail("example.WidgetType", j.history) | |
} | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment