Skip to content

Instantly share code, notes, and snippets.

@mrnovalles
Created April 16, 2015 19:00
Show Gist options
  • Save mrnovalles/71d3a3070fe00ca4caae to your computer and use it in GitHub Desktop.
Save mrnovalles/71d3a3070fe00ca4caae to your computer and use it in GitHub Desktop.
def caseClassToParams(cc: Product) = {
val fields = cc.getClass.getDeclaredFields.map(_.getName)
val keyValues = fields.zip(cc.productIterator.to).toList
keyValues.flatMap {
case ("foo", v) => {
val values = v.toString.split("&").toList
values.map{ p =>
val pair = p.split("=")
(pair.head, pair.last)
}
}
case (k, v) => List((k, v.toString))
}.toMap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment