Skip to content

iterableWrites2 causes Map.map(...) to be written as a seq of tuples #1151

@vhminh

Description

@vhminh

Play JSON Version (2.5.x / etc)

3.0.4

API (Scala / Java / Neither / Both)

Scala

Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)

MacOS

JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)

openjdk version "17.0.11" 2024-04-16 LTS
OpenJDK Runtime Environment Corretto-17.0.11.9.1 (build 17.0.11+9-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.11.9.1 (build 17.0.11+9-LTS, mixed mode, sharing)

Library Dependencies

None

Expected Behavior

Map.map(...) should be written as a json object
For example, this test should pass

"JsValueWrapper conversion" should {
  "convert Map.map(...) to json object, not json array" in {
    import Writes._
    Json.obj("data" -> Map("key" -> "value").map(identity))
      .mustEqual(Json.obj("data" -> Json.obj("key" -> "value")))
  }
}

Actual Behavior

The above test case fails with output:

[info] - should convert Map.map(...) to json object, not json array *** FAILED *** (2 milliseconds)
[info]   {"data":[["key","value"]]} did not equal {"data":{"key":"value"}} (JsonSharedSpec.scala:464)
[info]   Analysis:
[info]   JsObject(underlying: ImmutableLinkedHashMap("data": [["key","value"]] -> {"key":"value"}))
implicit def iterableWrites3[A, I[_]](implicit ev: I[A] <:< Iterable[A], w: Writes[A]): Writes[I[A]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions