From eed1458dce6f05d83675ef5400717702e61d7627 Mon Sep 17 00:00:00 2001 From: Stephane Godbillon Date: Tue, 5 Mar 2024 09:51:13 -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]]=20(#993)?= 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. (cherry picked from commit a842fafa6af97f23aa6e792a3d2ae29aae3ff108) --- .../shared/src/main/scala/play/api/libs/json/Writes.scala | 2 +- .../src/test/scala/play/api/libs/json/WritesSharedSpec.scala | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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..7deadf4f 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 @@ -366,7 +366,7 @@ 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 + 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]] 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..728b0fef 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,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 {