I have a Scala class class
case class Example(name: String, number: Int)
and companion object
object Example {
implicit object ExampleFormat extends Format[Example] {
def reads(json: JsValue) = {
JsSuccess(Example(
(json \ "name").as[String],
(json \ "number").as[Int]))
}
def writes(...){}
}
}
which converts JSON to a Scala object.
When JSON is valid (ie {"name":"name","number": 0}, it works fine, however when. numberIs in quotes {"name":"name","number":"0"}, I get an error message: validate.error.expected.jsnumber.
Is there a way to implicitly convert Stringto Intin that case (assuming the number is valid)?
source
share