Created
August 16, 2015 19:06
-
-
Save cloudcalvin/a5d76090a8f780ce8fe3 to your computer and use it in GitHub Desktop.
Print Scala class members fields with types
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 Implicits { | |
| implicit class CaseClassToString(c: AnyRef) { | |
| def toStringWithFields: String = { | |
| val fields = (Map[String, Any]() /: c.getClass.getDeclaredFields) { (a, f) => | |
| f.setAccessible(true) | |
| a + (f.getName -> f.get(c)) | |
| } | |
| s"${c.getClass.getName}(${fields.mkString(", ")})" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment