Skip to content

Instantly share code, notes, and snippets.

@yurifedoseev
Created August 4, 2015 15:13
Show Gist options
  • Save yurifedoseev/14f6072efc4d14d73b20 to your computer and use it in GitHub Desktop.
Save yurifedoseev/14f6072efc4d14d73b20 to your computer and use it in GitHub Desktop.
/**
* 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