Skip to content

Instantly share code, notes, and snippets.

@edeustace
Created January 10, 2014 17:23
Show Gist options
  • Save edeustace/8358527 to your computer and use it in GitHub Desktop.
Save edeustace/8358527 to your computer and use it in GitHub Desktop.
Java -> scala conversion of nested types
package org.corespring
import org.specs2.mutable.Specification
import scala.collection._
class JavaConversionsSpec extends Specification {
import scala.collection.JavaConversions._
def contributors : java.util.Map[String, java.util.Collection[String]] = new java.util.HashMap[String,java.util.Collection[String]]()
def convert(input:mutable.Map[String,Seq[String]]):String= "{}"
implicit def converter(in : java.util.Map[String, java.util.Collection[String]]) : mutable.Map[String,Seq[String]] = {
mapAsScalaMap(in).map( (kv) => kv._1 -> collectionAsScalaIterable(kv._2).toSeq)
}
"JavaConversions" should {
"make it possible to call convert with a java structure" in {
convert(contributors) === "{}"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment