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

前端 未结 4 1554
时光取名叫无心
时光取名叫无心 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:18

    Json combinators doesn't work for single field case class.

    Pascal (writer of this API) has explained this situation here https://groups.google.com/forum/?fromgroups=#!starred/play-framework/hGrveOkbJ6U

    There are some workarounds which works, like this one:

    case class A(value: List[Int])
    val areads = (__ \ 'value).read[List[Int]].map{ l => A(l) } // covariant map
    

提交回复
热议问题