The error means that it doesn't know how to serialize ObjectId
and expects you to provide a Writer
for it. This is one way to serialize it:
object Post {
implicit val objectIdWrites = new Writes[ObjectId] {
def writes(oId: ObjectId): JsValue = {
JsString(oId.toString)
}
}
implicit val implicitPostWrites = Json.writes[Post]
}
More information and explanations are available here.