Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created March 7, 2015 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanparsons/71d9fae9e0733c42d341 to your computer and use it in GitHub Desktop.
Save seanparsons/71d9fae9e0733c42d341 to your computer and use it in GitHub Desktop.
Decoding an enum.
implicit val myEnumDecodeJson: DecodeJson[MyEnum] = DecodeJson{hCursor =>
hCursor.focus match {
case `myEnumValue1Json` => DecodeResult.ok(MyEnumValue1)
case `myEnumValue2Json` => DecodeResult.ok(MyEnumValue2)
case _ => DecodeResult.fail("Expected MyEnum.", hCursor.history)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment