r3doc
r3doc

Reputation: 69

Too many arguments for method mapping: (apply: (String, models.Address) => R)(unapply: R => Option[(String, models.Address)])play.api.data.Mapping[R]

I have two case classes like this.

case class Company(name: String, address: Address)
case class Address(address1: String, address2: String, 
                   city: String, state: String, 
                   zip:String, country: String)

In my Application.scala I defined the following.

[1]. val companyForm = Form(of(Company.apply _, Company.unapply _)(
    "name" -> text,
    "address" -> mapping(
        "address1" -> nonEmptyText,
        "address2" -> text,
        "city" -> nonEmptyText,
        "state" -> nonEmptyText,
        "zip" -> nonEmptyText,
        "country" -> nonEmptyText
    )(Address.apply)(Address.unapply)
  )
)

[2]. val companyForm = Form(mapping(
    "name" -> text,
    "address" -> mapping(
        "address1" -> nonEmptyText,
        "address2" -> text,
        "city" -> nonEmptyText,
        "state" -> nonEmptyText,
        "zip" -> nonEmptyText,
        "country" -> nonEmptyText
    )(Address.apply)(Address.unapply)
  )(Company.apply, Company.unapply)
)

Right now [1] works for me but when I try to convert it to [2] it gives me the following error:

Too many arguments for method mapping: (apply: (String, models.Address) => R)(unapply: R => Option[(String, models.Address)])play.api.data.Mapping[R].

Please suggest me what I am doing wrong. Thanks in advance.

Upvotes: 3

Views: 1338

Answers (1)

arussinov
arussinov

Reputation: 1237

As methode of() is depricated, your form must be look like this:

     val companyForm = Form(
    mapping(
    "name" -> text,
    "address" -> mapping(
      "address1" -> nonEmptyText,
      "address2" -> text,
      "city" -> nonEmptyText,
      "state" -> nonEmptyText,
      "zip" -> nonEmptyText,
      "country" -> nonEmptyText
    )(Address.apply)(Address.unapply)
  )(Company.apply)(Company.unapply)
  )

So your problem is in the syntax bellow Company.Apply and Company.unapply methods

Upvotes: 1

Related Questions