From a662ff12b4d22442f657fc03802df633e6fa00ba Mon Sep 17 00:00:00 2001 From: Stephane Godbillon Date: Sun, 3 Mar 2024 10:55:40 -0800 Subject: [PATCH] =?UTF-8?q?Fix=20#974=20=E2=80=93=20Scala=203=20macro=20ca?= =?UTF-8?q?nnot=20find=20Writes=20for=20Seq[Map[String,=20T]]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moved the deprecated method `DefaultWrites.mapWrites` into `LowPriorityWrites` to get rid of the ambiguity. --- .../src/main/scala/play/api/libs/json/Writes.scala | 12 ++++++------ .../scala/play/api/libs/json/WritesSharedSpec.scala | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/play-json/shared/src/main/scala/play/api/libs/json/Writes.scala b/play-json/shared/src/main/scala/play/api/libs/json/Writes.scala index 8872c2fd..5f21a1ce 100644 --- a/play-json/shared/src/main/scala/play/api/libs/json/Writes.scala +++ b/play-json/shared/src/main/scala/play/api/libs/json/Writes.scala @@ -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]] @@ -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. */ diff --git a/play-json/shared/src/test/scala/play/api/libs/json/WritesSharedSpec.scala b/play-json/shared/src/test/scala/play/api/libs/json/WritesSharedSpec.scala index f8c76508..3a0b321a 100644 --- a/play-json/shared/src/test/scala/play/api/libs/json/WritesSharedSpec.scala +++ b/play-json/shared/src/test/scala/play/api/libs/json/WritesSharedSpec.scala @@ -84,6 +84,9 @@ 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 {