Frage

Why does this code cause an error

import org.json4s.native.JsonMethods._
import org.json4s._

object Application extends App {
  implicit val formats = DefaultFormats
  val js = JString("120.0")
  val d = js.extract[Double]
  println(d)
}

it says Exception in thread "main" org.json4s.package$MappingException: Do not know how to convert JString(120.0) into double

War es hilfreich?

Lösung

Probably because Double is not a case class and doesn't have a constructor taking a String for argument.

How about js.extract[String].toDouble

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top