ScalaJS: how to parse ajax response from JSON to a case class

611 views Asked by At

I'm trying ScalaJS with Play! Scala 2.4 and the serialization library for Scala uPickle.

I don't manage to parse the return of an AJAX call.

Here is my case class:

@JSExportAll
case class Room(id: String, name: String, presentation: String, images: Seq[String], isAnApartment: Boolean )

I have a controller on the server side returning a sequence of rooms:

 val rooms = Seq(room1, room2, room3)
 def findAll() = Action {
   Ok(write(rooms))
 } 

(Rooms are some instance of the Room class.)

Now I want to deserialize these object on the client side. Here is the snippet of code which does not work:

Ajax.get("/rooms")
  .onSuccess { case response =>
     read[Seq[Room]](response.responseText)
  }

but I get this runtime exception:

RuntimeException: There were linking errors

What I want to do seems very easy but I don't manage to make it work, any hints would be appreciated.

0

There are 0 answers