-
-
Save Jacoby6000/6bd09fd81fcfde582ae9ff5e8a7af0b7 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
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