Created
July 15, 2016 01:11
-
-
Save trane/f1ba48cadd8fbe2de6378808b6c73cd8 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
def writes(o: T): JsObject = { | |
val canonicalName = Option(clazz.getCanonicalName()).getOrElse(throw new IllegalArgumentException("Cannot serialize this class because its canonical name is null. This is most likely because it is an Array or a Local or Anonymous class.")) | |
JsObject(Seq("className" -> JsString(canonicalName))) | |
} | |
// i find using the container type in one place better for understanding | |
// since we are threading transformations and operations on the Option until | |
// the end when we either have a result or we throw an exception | |
def writes(o: T): JsObject = | |
Option(clazz.getCanonicalName()) | |
.map(JsObject(Seq("className" -> JsString(_)))) | |
.getOrElse(throw new IllegalArgumentException("Cannot serialize this class because its canonical name is null. This is most likely because it is an Array or a Local or Anonymous class."))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment