1

I have a case class with a 2-dimensional array stored in a MongoDB, because Salat does not support Arrays I'm trying to write my own converters.

case class Matrix(id: String, matr: Array[Array[Int]])

implicit def toDBObject(m: Matrix) = MongoDBObject(
    "id" -> m.id,
    "matr" -> s.matr
)

implicit def toMatr(in: MongoDBObject) =  Matrix(
    in.as[String]("id"),
    in.as[Array[Array[Int]]]("matr") // This does not work
)

toDBObject works fine, but the toMatr is not working. How can I make this work?

user4007301
  • 67
  • 2
  • 9

1 Answers1

1

I managed to get it working with yield and two for loop:

 for (e <- in.as[MongoDBList]("matr").toArray)
   yield for (x <- e.asInstanceOf[BasicDBList].toArray) yield x.asInstanceOf[Int]

this converts the 2d MongoDBList to a 2d Scala Array

user4007301
  • 67
  • 2
  • 9