How to write a Play JSON writes converter for a case class with a single nullable member

前端 未结 2 1105
鱼传尺愫
鱼传尺愫 2020-12-29 10:56

In Play 2.3, I have a case class with a single optional double member:

case class SomeClass(foo: Option[Double])

I need a JSON write conver

2条回答
  •  不思量自难忘°
    2020-12-29 11:46

    The easy way is:

    import play.api.libs.json.Json
    
    implicit val fmt = Json.format[SomeClass]
    

    Which uses a macro to auto-generate the json format for you. Beats implementing writes directly.

提交回复
热议问题