How to turn json to case class when case class has only one field

前端 未结 4 1556
时光取名叫无心
时光取名叫无心 2020-11-28 23:59

In play 2.1 reads are used to marshall Json to objects. But how can I do this when the case class has only one field. The ideom that works for more fields does not work, as

4条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 00:20

    Even simpler solution than the accepted one:

    case class A(value: String)
    val reads = (__ \ "key").read[String].map(A.apply)
    

提交回复
热议问题