Created
January 5, 2017 21:06
-
-
Save zeryx/8cce0df844d02e2368a344c18b9fdefc to your computer and use it in GitHub Desktop.
This file contains 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
//reads input string, checks if its json, and if it is returns an encoded object of the first type that parses correctly. | |
def Read[SomeType](input: String): Option[SomeType] = { | |
//maybe I need to loop over every defined codec I've generated? How woud I do that? | |
val decoder: DecodeJson[SomeType] = DecodeJson.of[SomeType] | |
JsonParser.parse(input).toOption match { | |
case None => { | |
throw new AlgorithmException(s"input failed to parse.") | |
} | |
case Some(json: Json) => { | |
val decoded = decoder.decodeJson(json).toOption | |
decoded | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment