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

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

    Based on @yokomizor's answer, I found the simplest solution to create a Formatter to be

    case class Person(name: String)
    val personFormatter: Format[Person] =
      (__ \ "full_name").format[String].inmap(Person.apply, unlift(Person.unapply))
    

提交回复
热议问题