Skip to content

Commit

Permalink
Fix #974 – Scala 3 macro cannot find Writes for Seq[Map[String, T]]
Browse files Browse the repository at this point in the history
Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity.
  • Loading branch information
sgodbillon committed Mar 4, 2024
1 parent 10a8ae1 commit 1107a14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions play-json/shared/src/main/scala/play/api/libs/json/Writes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ trait DefaultWrites extends LowPriorityWrites with EnumerationWrites {
}
}

/**
* Serializer for Map[String,V] types.
*/
@deprecated("Use `genericMapWrites`", "2.8.0")
implicit def mapWrites[V: Writes]: OWrites[MapWrites.Map[String, V]] = MapWrites.mapWrites

implicit def keyMapWrites[K: KeyWrites, V: Writes, M[K, V] <: MapWrites.Map[K, V]]: OWrites[M[K, V]] = {
val kw = implicitly[KeyWrites[K]]
val vw = implicitly[Writes[V]]
Expand Down Expand Up @@ -521,6 +515,12 @@ sealed trait LowPriorityWrites extends EnvWrites {
def iterableWrites[A, M[T] <: Iterable[T]](implicit w: Writes[A]): Writes[M[A]] =
iterableWrites2[A, M[A]]

/**
* Serializer for Map[String,V] types.
*/
@deprecated("Use `genericMapWrites`", "2.8.0")
implicit def mapWrites[V: Writes]: OWrites[MapWrites.Map[String, V]] = MapWrites.mapWrites

/**
* Serializer for Iterable types.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ final class WritesSharedSpec extends AnyWordSpec with Matchers {
"write lazy maps" in {
Json.toJson(Map("a" -> 1).map(kv => kv._1 -> (kv._2 + 1))).mustEqual(Json.obj("a" -> 2))
}

"write a map nested in a seq" in {
Json.toJson(Seq(Map("a" -> 1))).mustEqual(Json.arr(Json.obj("a" -> 1)))
}
}

"Iterable writes" should {
Expand Down

0 comments on commit 1107a14

Please sign in to comment.