I am trying to use Scala + Play 2.4.2 on a side project, I was writing a json parser and IntelliJ suggested this fix for my syntax.
I can't understand what this means
For me this (Person.apply, _)
should be written (Person.apply _)
, but like that I get a cannot resolve symbol apply
and the code does not compile.
Since I have an overloaded constructor shouldn't (Person.apply _)
call it with the parameters from the valuereads
function?
package models
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class Person(id: Long = 0, name: String, age: Int){
def this(name: String, age: Int) = this(0, name, age)
}
object Person {
implicit val personFormat = Json.format[Person]
implicit val valuereads = (__ \ "value").read {(
(__ \ "name").read[String] and
(__ \ "age").read[Int]
)(Person.apply, _) //**<=== THIS, what apply, _ stands for**
def apply(name: String, age: Int) = new Person(name, age)
}
The fixed syntax still does not compile, but I get no warnings. What am I doing wrong here?
BTW I am following this info : https://www.playframework.com/documentation/2.4.x/ScalaJsonCombinators