title: Scala Akka (un)marshalling nested Seq collections with Spray JSON
body: <p>I'm trying to use Spray JSON to marshall the 'Seq' collection below into a 'BidRequest' entity with the parameters as defined.
  The Seq collection is mostly nested, therefore some 'Seq' parameter fields also have variable collection types that need to be marshalled.
  Then after a computation, the aim is to unmarshall the results as an entity of 'BidResponse'.</p>
  <p>What's the best approach to do this?</p>
  <p>I'm using Akka-HTTP, Akka-Streams, Akka-Actor.</p>
  <p>Seq collection:</p>
  <pre class="lang-scala prettyprint-override"><code>
        val activeUsers = Seq(
            Campaign(
                id = 1,
                country = &quot;UK&quot;,
                targeting = Targeting(
                    targetedSiteIds = Seq(&quot;0006a522ce0f4bbbbaa6b3c38cafaa0f&quot;) 
                    ),
                    banners = List(
                        Banner(
                            id = 1,
                            src =&quot;https://business.URLTV.com/wp-content/uploads/2020/06/openGraph.jpeg&quot;,
                            width = 300,
                            height = 250
                            )
                          ),
                    bid = 5d
                  )
              )
  
  </code></pre>
  <p>BidRequest case class:</p>
  <pre class="lang-scala prettyprint-override"><code>case class BidRequest(id: String, imp: Option[List[Impression]], site:Site, user: Option[User], device: Option[Device])
  </code></pre>
  <p>BidResponse case class:</p>
  <pre class="lang-scala prettyprint-override"><code>case class BidResponse(id: String, bidRequestId: String, price: Double, adid:Option[String], banner: Option[Banner])
  </code></pre>
  <p>The other case classes:</p>
  <pre class="lang-scala prettyprint-override"><code>
  case class Campaign(id: Int, country: String, targeting: Targeting, banners: List[Banner], bid: Double)
  case class Targeting(targetedSiteIds: Seq[String])
  case class Banner(id: Int, src: String, width: Int, height: Int)
  
  case class Impression(id: String, wmin: Option[Int], wmax: Option[Int], w: Option[Int], hmin: Option[Int], hmax: Option[Int], h: Option[Int], bidFloor: Option[Double])
  case class Site(id: Int, domain: String)
  case class User(id: String, geo: Option[Geo])
  case class Device(id: String, geo: Option[Geo])
  case class Geo(country: Option[String])
  
  </code></pre>
  <p>I've so far tried using the code below but keep getting type mismatch errors:</p>
  <pre class="lang-scala prettyprint-override"><code>import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
  import spray.json.DefaultJsonProtocol._
  
  implicit val resFormat = jsonFormat2(BidResponse)
  implicit val bidFormat = jsonFormat1(BidRequest)
  implicit val cFormat = jsonFormat1(Campaign)
  implicit val tFormat = jsonFormat1(Targeting)
  implicit val bFormat = jsonFormat1(Banner)
  implicit val iFormat = jsonFormat1(Impression)
  implicit val sFormat = jsonFormat1(Site)
  implicit val uFormat = jsonFormat1(User)
  implicit val dFormat = jsonFormat1(Device)
  implicit val gFormat = jsonFormat1(Geo)
  </code></pre>