'Slick using mapped column type in update statement

I have a trouble in using slick MappedColumnType, the code snippet is as following:

private trait UserTable {
  self: HasDatabaseConfigProvider[JdbcProfile] =>

  import driver.api._

  lazy val userTable = TableQuery[User]

  class UserTable(tag: Tag)
    extends Table[User](tag, "user") {

    implicit def mapper = MappedColumnType.base[JsObject, String](
      { scope: JsObject => scope.toString }, { s: String => Json.parse(s).as[JsObject] }
    )

    val id = column[Long]("id", O.PrimaryKey, O.AutoInc)
    val name = column[String]("name")
    val hobby = column[JsObject]("hobby")

    def * = (id, name, hobby) <> (User.tupled, User.unapply)
  }

}

My User case class is defined as follow:

case class User(id: Long, name: String: hobby: JsObject)

I have corresponding insert and update statement for my database. However the following update statement is not working for me.

  def updateQuery(id: Long, newUser: User) = {
    userTable.filter(x => x.id === id)
      .map(x => (x.hobby))
      .update(newUser.hobby)

It will throw a compile error:

No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).

I think it's pretty straight-forward. Is there something I did wrong?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source