从json构造的Scala eclipse调试器当前类不清楚
我有一个包含scala中列表的类。从json构造的Scala eclipse调试器当前类不清楚,json,eclipse,scala,playframework,playframework-2.1,Json,Eclipse,Scala,Playframework,Playframework 2.1,我有一个包含scala中列表的类。 我不理解调试器(eclipse)的结构 为什么项目不在同一行中?“X”是因为此列表被标记为选项[list[String]。。“tl”从何而来?? 为什么实际包含字符串列表的“值”不在同一位置(兄弟) Json: { "id": "1", "references": { "configuratorId": "conf id", "seekId": "seekid", "hsId": "hsid", "fpId": "fp
我不理解调试器(eclipse)的结构 为什么项目不在同一行中?“X”是因为此列表被标记为选项[list[String]。。“tl”从何而来??
为什么实际包含字符串列表的“值”不在同一位置(兄弟) Json:
{
"id": "1",
"references": {
"configuratorId": "conf id",
"seekId": "seekid",
"hsId": "hsid",
"fpId": "fpid"
},
"defaultName": "Product 1 - default name",
"defaultDescription": "Product 1 - default desc",
"categories": [
"string1",
"string2"
]
}
类别:
case class MiniProduct(id: Option[String], defaultName: String, defaultDescription:String, references: References, categories:Option[List[String]])
{}
类格式:
implicit val miniProductFormat = new Format[MiniProduct]{
def writes(item: MiniProduct):JsValue = {
Json.obj(
"id" -> item.id,
"defaultName" -> item.defaultName,
"defaultDescription" -> item.defaultDescription,
"references" -> item.references,
"categories" -> item.categories
)
}
def reads(json: JsValue): JsResult[MiniProduct] =
JsSuccess(new MiniProduct(
(json \ "id").as[Option[String]],
(json \ "defaultName").as[String],
(json \ "defaultDescription").as[String],
(json \ "references").as[References],
(json \ "categories").as[Option[List[String]]]
))
}
控制器:
def addProducts(lang: String, t: String) = Action {
request =>
request.body.asJson.map {
json =>
val req = json.as[MiniProduct]
println("Printing list of categories: ")
req.categories.foreach(println)
输出正常:
Printing list of categories:
List(string1, string2)
这是因为它是一个(据我所知,它是Scala中List()的默认实现)如果使用,可以启用“显示逻辑结构”(Variables视图右上角的小树状按钮)。这将显示一个列表,如下图所示: