Skip to content

Instantly share code, notes, and snippets.

@ndeloof
Created February 5, 2014 08:33
Show Gist options
  • Save ndeloof/8819372 to your computer and use it in GitHub Desktop.
Save ndeloof/8819372 to your computer and use it in GitHub Desktop.
play List JSON serialization
No Json deserializer found for type List[models.Subscription]. Try to implement an implicit Writes or Format for this type.
In /Volumes/HD/Users/nicolas/Boulot/cloudbees/je-sp/app/controllers/API.scala at line 25.
val subscriptions: List[Subscription] = ???
22 Ok(
23 Json.obj("account" -> account.getName,
24 "salesforce_id" -> account.getId,
25 "subscriptions" -> subscriptions,
26 "licenses" -> "TODO",
27 "credits" -> "TODO")
class Subscription(...) extends Writes[Subscription]{
def writes(o: Subscription): JsValue = {
Json.obj(
"product" -> product,
"expiration" -> FastDateFormat.getInstance("dd-MM-yyyy").format(expiration))
}
}
@mandubian
Copy link

What is class Subscription(...) extends Writes[Subscription] ?

You need to provide an implicit val/object implementing Writes[Subscription].

You can put it in the companion object Subscription to have it implicitly with any instance of Subscription.

@dgouyette
Copy link

You can also try if you don't want to implement your own Writer

implicit val subscriptionFormat = Json.format[Subscription]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment