Skip to content

Commit

Permalink
Add tests for field ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Donovan Levinson committed May 11, 2024
1 parent 51bd5d6 commit cff4e97
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class JsonSharedSpec extends AnyWordSpec with Matchers with org.scalatestplus.sc
(__ \ Symbol("models")).format[Map[String, String]]
)(Car.apply, c => (c.id, c.models))

case class Model(m1: Option[String], c: String, z: Option[Double], a: Int, b: Option[String])

implicit val modelFormat: Format[Model] = Json.format[Model]

def json[T](f: JsonFacade => T) = forAll(Gen.oneOf(Json, Json.configured, Json.using[Json.MacroOptions]))(f)

"JSON" should {
Expand Down Expand Up @@ -443,6 +447,12 @@ class JsonSharedSpec extends AnyWordSpec with Matchers with org.scalatestplus.sc

test.toString.mustEqual(js.parse(req).toString) // ).ignoreSpace
}

"preserve field ordering" in {
val model = Model(Some("foo"), "bar", Some(1.2), 42, Some("baz"))
val serialized = Json.stringify(Json.toJson(model))
serialized.mustEqual("""{"m1":"foo","c":"bar","z":1.2,"a":42,"b":"baz"}""")
}
}

// ---
Expand Down

0 comments on commit cff4e97

Please sign in to comment.