I'm trying to implement JasperReport generation in Scala. I need to take the information from memory and merge it with the report.
This is what the documentation says, in Java:
HashMap[] reportDataSource = new HashMap[4];
// fill reportDataSource with information
JRMapArrayDataSource dataSource = new JRMapArrayDataSource(reportDataSource);
JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream,
new HashMap(), dataSource);
This is my attempt in Scala, where I get a compilation error in the line noted below:
val row1 = HashMap[String,String]("code" -> "B1", "name" -> "Bank 1")
val row2 = HashMap[String,String]("code" -> "B2", "name" -> "Bank 2")
val map = Array[HashMap[String,String]](row1,row2)
val reportDataSource = new JRMapArrayDataSource(map) // <-- this line does not compile
val baos = new ByteArrayOutputStream
JasperRunManager.runReportToPdfStream(blob.getBinaryStream, baos, params, reportDataSource)
Ok(baos.toByteArray).as("application/pdf")
The error (cannot convert from HashMap to Array[Object]):
type mismatch; found : Array[scala.collection.mutable.HashMap[String,String]] required: Array[Object] Note: scala.collection.mutable.HashMap[String,String] <: Object, but class Array is invariant in type T. You may wish to investigate a wildcard type such as _ <: Object. (SLS 3.2.10)>
How to do the conversion and fix the problem?