El formateador Scala no puede serializar una cadena json que distingue entre mayúsculas y minúsculas
Frecuentes
Visto 281 equipos
0
I wrote my own play.api.libs.json.Format for a class i am read/writing as JSON.
My goal is to build the following class:
WallpaperItem(title:String, filename:String, tileSize:Option[String], url:Option[String])
The JSON formatter looks like:
val wallpaperItemFormat= new Format[WallpaperItem] {
def writes(data: WallpaperItem): JsValue = {
Json.obj(
"title" -> data.title,
"filename" -> data.filename,
"tileSize" -> data.tileSize,
"url" -> data.url
)}
def reads(json: JsValue): JsResult[WallpaperItem] = {
JsSuccess(new WallpaperItem(
(json \ "title").as[String],
(json \ "filename").as[String],
(json \ "tileSize").as[Option[String]],
(json \ "url").as[Option[String]]
))}
}
The JSON string in debug is:
{
"title": "MILANO STRIA",
"filename": "MS21-74.jpg",
"tileSize": 32,
"url": "http://www.koroseal.com/images/designs_large/MS21-74.jpg"
}
1 Respuestas
1
The json you are trying to format is Int, and you try to read it as String. You should do: Change WallpaperItem to have tileSize:Option[Int] Or convert the optional Int to Optional String before constructing the WallpaperItem object
contestado el 28 de mayo de 14 a las 12:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas json scala or haz tu propia pregunta.