All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.api.libs.json.MapWrites.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc. 
 */

package play.api.libs.json

import scala.collection.IterableOps
import scala.collection.MapOps

object MapWrites {
  type Map[K, V] = MapOps[K, V, CC, _]

  // see scala.collection.AnyConstr
  private[json] type AnyConstr[X] = Any

  // see scala.collections.MapOps
  private[json] type CC[X, +Y] = IterableOps[_, AnyConstr, _]

  /**
   * Serializer for Map[String,V] types.
   */
  def mapWrites[V: Writes]: OWrites[Map[String, V]] = {
    val w = implicitly[Writes[V]]

    OWrites[Map[String, V]] { ts =>
      JsObject(ts.iterator.map(kv => kv._1 -> w.writes(kv._2)).toSeq)
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy