Deepak
Deepak

Reputation: 361

In playframework, do we need to always override unbind method when implementing QueryStringBindable?

https://www.playframework.com/documentation/2.8.0/api/scala/play/api/mvc/QueryStringBindable.html

The example and many other examples always implement bind and unbind when creating a OueryStringBindable implicit, do we really need to implement both ?

Upvotes: 0

Views: 86

Answers (1)

cchantep
cchantep

Reputation: 9168

Both QueryStringBindable.{unbind,bind} are abstracts, so they need to be implemented (not overriden as there is no default implementation in the trait).

A QueryStringBindable can be also be derived from the provided one.

case class Foo(name: String)

object Foo {
  // Derive with `transform` ...
  implicit val queryStringBindable: QueryStringBindable[Foo] = 
    implicitly[QueryStringBindable[String]].transform[Foo](
      { name: String => Foo(name) },
      { foo: Foo => foo.name })
}

Upvotes: 1

Related Questions