title: No Json serializer as JsObject found for type model.User. Try to implement an implicit OWrites or OFormat for this type
body: <p>I'm using Play framework with Scala and Reactive Mongo to save an object into my mongodb database. Following this <a href="http://reactivemongo.org/releases/0.10/documentation/bson/usage.html" rel="nofollow noreferrer">http://reactivemongo.org/releases/0.10/documentation/bson/usage.html</a> I came up with the following code:</p>
  
  <pre><code>import java.util.Date
  
  import com.google.inject.Inject
  import model.User
  import play.modules.reactivemongo.ReactiveMongoApi
  import play.modules.reactivemongo.json.collection.JSONCollection
  import reactivemongo.bson.{BSONDocument, BSONDocumentReader, BSONDocumentWriter, BSONObjectID}
  import play.modules.reactivemongo.json._, ImplicitBSONHandlers._
  import json.JsonFormatters._
  
  class UserRepository @Inject() (val reactiveMongoApi : ReactiveMongoApi) {
  
    private def users = reactiveMongoApi.db.collection[JSONCollection]("users")
  
    def save(user: User) = {
      users.insert(user)
    }
  
    implicit object UserWriter extends BSONDocumentWriter[User] {
      def write(user: User) = {
        BSONDocument(
          "_id" -&gt; Option(user.id).getOrElse(BSONObjectID.generate),
          "name" -&gt; user.name,
          "email" -&gt; user.email,
          "companyName" -&gt; user.companyName,
          "created" -&gt; Option(user.created).getOrElse(new Date)
        )
      }
    }
  
    implicit object UserReader extends BSONDocumentReader[User] {
      def read(doc: BSONDocument): User = {
        User(
          doc.getAs[BSONObjectID]("_id").get,
          doc.getAs[String]("name").get,
          doc.getAs[String]("email").get,
          doc.getAs[String]("companyName").get,
          doc.getAs[Date]("created").get
        )
      }
    }
  }
  </code></pre>
  
  <p>I created my implicit writers to convert to a BsonDocument, so I was expecting it to be properly converted and saved into the database.</p>
  
  <p>However, when I compile, I get:</p>
  
  <pre><code>UserRepository.scala:18: No Json serializer as JsObject found for type model.User. Try to implement an implicit OWrites or OFormat for this type.
  [error] Error occurred in an application involving default arguments.
  [error]     users.insert(user)
  </code></pre>
  
  <p>I'm importing necessary packages as mentioned in <a href="https://stackoverflow.com/questions/31142366/no-json-serializer-as-jsobject-found-for-type-play-api-libs-json-jsobject#">No Json serializer as JsObject found for type play.api.libs.json.JsObject</a>.
  I'm also importing json.JsonFormatters._ which includes:</p>
  
  <pre><code>implicit val userWrites : Format[User] = Json.format[User]
  </code></pre>
  
  <p>Yet, it's still returning the same error telling me it can't convert from JsObject to User. I fail to see where is the JsObject here, considering my User entity is just a case class with 5 fields. </p>
  
  <pre><code>case class User(var id: BSONObjectID, var name: String, var email: String, var companyName: String, var created: Date) {
  }
  </code></pre>
  
  <p>Any ideas? What am I missing?</p>