I am trying to convert a java.util.List to a Scala list. There are many possibilities presented in post 674713 so I would like to know which one is the the best. I am using Play 2.1.1. My model is :
case class Page[T](
var data: java.util.List[T],
var previous: String,
var next: String,
var totalPageCount: Int)(implicit val tWrites: Writes[T])
object Page {
implicit def pageWrites[T: Writes]: Writes[Page[T]] = (
(__ \ 'data).write[java.util.List[T]] and
(__ \ 'previous).write[String] and
(__ \ 'next).write[String] and
(__ \ 'totalPageCount).write[Int])(unlift(Page.unapply[T]))
}
This code does not work because I need to add a writer for generic java.util.List[T] type.
I have added this to my object Page :
implicit def listWrites[T](implicit fmt: Writes[T]): Writes[List[T]] = new Writes[List[T]] {
def writes(ts: List[T]) = JsArray(ts.map(t => Json.toJson(t)(fmt)))
}
But this generates an error when executing my project ("MatchError: null" on listWrites). Therefore I would like to convert my java.util.List to a Scala one to avoid using this writer that does not work. Any solution ?