Created
August 4, 2015 15:13
-
-
Save yurifedoseev/14f6072efc4d14d73b20 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
/** | |
* Created by Yuri on 04.08.2015. | |
*/ | |
object Utils { | |
def mapClassToSeq(mes: AnyRef) = { | |
mes.getClass.getDeclaredFields.map(f => { | |
f.setAccessible(true) | |
camelToUnderscores(f.getName) -> f.get(mes) | |
}).toSeq | |
} | |
def camelToUnderscores(name: String) = "[A-Z\\d]".r.replaceAllIn(name, {m => | |
"_" + m.group(0).toLowerCase() | |
}) | |
} | |
case class Message(chatId: Int, textContent: String, lastUpdatedGroupId: Int) | |
object Main extends App { | |
val message = Message(2311, "Trololo", 3041212) | |
println(Utils.mapClassToSeq(message)) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment