I am new to scala and I need to convert a case class object to a json string using spray json. The case class look as below:
case class DriverDetails(userId : String, names : Option[List[String]], addresses : Option[List[Address]], invalidData : Option[Map[String, Map[String, List[String]]]], vehicleIds : List[String])
case class Address(street : Option[String], city : String, state : String, contactNumbers : List[String])
can someone please suggest how to convert the object of case class DriverDetails to json string?
Spray needs to know the format of the objects to serialize/deserialize them, so you should provide the formats. You can use helper functions to create format for the case classes:
Now, you can use
toJsonfunction: