Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created January 21, 2015 12:12
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 debasishg/a2c14c1b63cb18e76e9e to your computer and use it in GitHub Desktop.
Save debasishg/a2c14c1b63cb18e76e9e to your computer and use it in GitHub Desktop.
sealed trait Base
case class D1(...) extends Base
case class D2(...) extedns Base
// Have defined all instances of EncodeJson & DecodeJson for D1 and D2
// works in 6.0.x but does not compile in 6.1-M5 since DecodeResult is now invariant
implicit val decode: DecodeJson[Base] = DecodeJson { c =>
(c --\ "storeDelete").as[D1] |||
(c --\ "indexState").as[D2] |||
DecodeResult.fail(s"Unable to decode payload in [$c.asJson]", c.history)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment