FasterXML / FasterXML/jackson-module-scala
Sorting of case class properties no longer works as of 2.20
- Ngôn ngữ chính
- Scala
- Star
- 506
- Fork
- 138
- Merge trung bình
- 3 giờ 6 phút
- Pull request đã merge (30 ngày)
- 48
Mô tả
Can be reproduced with the following test case:
```diff
diff --git a/src/test/scala/com/fasterxml/jackson/module/scala/ser/CaseClassSerializerTest.scala b/src/test/scala/com/fasterxml/jackson/module/scala/ser/CaseClassSerializerTest.scala
index 6dc1d665..33dddf06 100644
--- a/src/test/scala/com/fasterxml/jackson/module/scala/ser/CaseClassSerializerTest.scala
+++ b/src/test/scala/com/fasterxml/jackson/module/scala/ser/CaseClassSerializerTest.scala
@@ -2,6 +2,9 @@ package com.fasterxml.jackson.module.scala.ser
import com.fasterxml.jackson.annotation.JsonProperty.Access
import com.fasterxml.jackson.annotation._
+import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.{ObjectMapper, PropertyNamingStrategies}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
@@ -62,6 +65,8 @@ case class PrivateDefaultFields(
case class ClassWithUnitField(field: Unit, intField: Int)
case class ClassWithOnlyUnitField(field: Unit)
+case class ClassWithUnorderedFields(f3: Int = 3, f2: Int = 2, f0: Int = 0, f1: Int = 1)
+
class CaseClassSerializerTest extends SerializerTest {
case class NestedClass(field: String)
@@ -207,4 +212,11 @@ class CaseClassSerializerTest extends SerializerTest {
serialize(GeneratedDefaultArgumentClass()) shouldEqual "{}"
}
+ it should "sort properties of the case class" in {
+ val mapper = newBuilder
+ .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
+ .build()
+ serialize(ClassWithUnorderedFields(), mapper) shouldEqual """{"f0":0,"f1":1,"f2":2,"f3":3}"""
+ }
+
}
```
This test cases passes with 2.19.2 and fails with 2.20.0. I thought it might be related to https://github.com/FasterXML/jackson-databind/issues/3900, but disabling `MapperFeature.SORT_CREATOR_PROPERTIES_FIRST` does not resolve the issue.
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.