Question

I'm trying to understand the following piece of code in the Activator reactive maps example. I would appreciate if someone can explain the ( __ \ "event") and ~ part of code.

 object UserPositions {
    implicit def userPositionsFormat: Format[UserPositions] = (
      (__ \ "event").format[String] ~
        (__ \ "positions").format[FeatureCollection[LatLng]]
      ).apply({
      case ("user-positions", positions) => UserPositions(positions)
    }, userPositions => ("user-positions", userPositions.positions))
  }
Was it helpful?

Solution

It is converting a Json object into Scala object and vice versa. (__ \ "event") means "event" element of Json object, and ~ means joining the elements into a tuple.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top