Serialize to json default value of Map type as a part of case class

226 Views Asked by At

I have a case class that includes a default value of Map[String, String].

something like that:

case class Car(brand: String, color: String, extraData: Map[String, String] = Map.empty[String, String])

I tried to create a custom json format for that:

implicit object carJsonFormat extends RootJsonFormat[Props]  {
    override def write(obj: Props): JsValue = ???

    override def read(json: JsValue): Props = ???
  }

but had difficulty with dealing with the Map type when I tried to override write and read.

Does anyone have an idea for an implementation?

0

There are 0 best solutions below