playframework/play-json

reader run error while match case class with one args

yangyongyongyong opened this issue · 1 comments

pom:

        <dependency>
            <groupId>com.typesafe.play</groupId>
            <artifactId>play-json_2.12</artifactId>
            <version>2.9.2</version>
        </dependency>

code:

package com.test

import play.api.libs.json._
import play.api.libs.json.Reads._
import play.api.libs.functional.syntax._


object ScalaTest {
    def main(args: Array[String]) = {


        val json1 =
            """
              |{
              |    "meanWeight": 100,
              |    "dd": {"id":"232323","id1":"232323"},
              |    "profileId": "dossierid231453",
              |    "dossierId": "dossierid2345235",
              |    "ccc": "ccc111",
              |    "faceClusterNum": 2
              |}
              |""".stripMargin


        // read报红原因:
        implicit val ReaderD1: Reads[D1] = (
            (JsPath \ "id").read[String]
//                and (JsPath \ "id1").read[String]
            )(D1.apply _)

        implicit val DossierWithMeanCentroidReader: Reads[DossierWithMeanCentroid] = (
            (JsPath \ "dossierId").read[String] and
                (JsPath \ "meanWeight").read[Int] and
                (JsPath \ "dd").read[D1]
            ) (DossierWithMeanCentroid.apply _)


        val value = Json.parse(json1).validate[DossierWithMeanCentroid]
        value match {
            case s: JsSuccess[DossierWithMeanCentroid] => println(s.get)
            case e: JsError => println(s"解析错误: ${e}")
        }

    }

    case class DossierWithMeanCentroid(dossier_id: String, meanWeight: Int, d: D1)

    case class D1(id: String)
//    case class D1(id: String,id1:String)


}

Hi, this issue tracker is for confirmed issue. Please rather ask on discord or SO.