diff --git a/play-json/shared/src/test/scala/play/api/libs/json/JsonSharedSpec.scala b/play-json/shared/src/test/scala/play/api/libs/json/JsonSharedSpec.scala index bdcba06a..163e63c3 100644 --- a/play-json/shared/src/test/scala/play/api/libs/json/JsonSharedSpec.scala +++ b/play-json/shared/src/test/scala/play/api/libs/json/JsonSharedSpec.scala @@ -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 { @@ -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"}""") + } } // ---