expert
expert

Reputation: 30125

How do I define json writer for custom object in Play + Scala?

Could you please demostrate how I can define json writer for my class in Scala and Play Framework 2.1-RC2 ?

The documentation is quite confusing (and will be significant obstacle for wider adoption of Scala/Play by web-developer community). For example not only it's unclear where exactly following code (taken from here) should be located

implicit val taskWrites = (
  (__ \ "id").write[String] ~
  (__ \ "label").write[Boolean] ~
)(unlift(Task.unapply))

but it's also not compilable if I put it inside object definition. Play gives me following error

not found: value __

Here is my Task.scala

http://pastebin.com/hG8F6Gqk

Upvotes: 1

Views: 1194

Answers (3)

Roch
Roch

Reputation: 22041

import play.api.libs.json._
import play.api.libs.functional.syntax._

Upvotes: 1

expert
expert

Reputation: 30125

Well, turned out the problem was obvious. I forgot to import play.api.libs.functional.syntax._.

Upvotes: 2

Ryan
Ryan

Reputation: 7247

The underscore you're using isn't a standard underscore.

Your underscore: __

ASCII Character #95: _

Upvotes: -1

Related Questions