Skip to content

Instantly share code, notes, and snippets.

@Jacoby6000
Forked from zeryx/def.scala
Last active January 5, 2017 22:44
Show Gist options
  • Save Jacoby6000/6bd09fd81fcfde582ae9ff5e8a7af0b7 to your computer and use it in GitHub Desktop.
Save Jacoby6000/6bd09fd81fcfde582ae9ff5e8a7af0b7 to your computer and use it in GitHub Desktop.
object Input {
implicit def inputCodec: CodecJson[Input] = {
def encoder(data: Input): Json =
data match {
case train: Train => Train.trainCodec.encode(train)
case predict: Predict => Predict.predictCodec.encode(predict)
}
def decoder(json: HCursor): DecodeResult[Input] =
Predict.predictCodec.decode(json).fold(
(failReason, cursor) => Train.trainCodec.decode(json),
successResult => DecodeResult.ok(successResult)
)
CodecJson[Input](encoder, decoder)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment