KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
there are two classes Foo and Bar . Foo contains a field of Bar . The question is, how do I implement an implicit json Writes for class Foo ? Here is the code: package models import play.api.libs.json._ case class Foo(id: String, bar: Bar) object Foo { implicit val implicitFooWrites = new Writes[Foo] { def writes(foo: Foo): JsValue = { Json.obj( "id" -> foo.id, "bar" -> foo.bar ) } } } case class Bar(x: String, y: Int) object Bar { implicit val implicitBarWrites = new Writes[Bar] { def writes(bar: Bar): JsValue = { Json.obj( "x" -> bar.x, "y" -> bar.y ) } } } When I try to compile, I get the following error: No Json deserializer found for type models.Bar. Try to implement an implicit Writes or Format for this type. I don't understand this compiler error, since I implemented an implicit Writes for models.Bar class. What is the problem here?
Tags (comma-separated)
Save Edits
Cancel