FasterXML / FasterXML/jackson-module-scala

Sorting of case class properties no longer works as of 2.20

Open
#772 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
Scala
Stars
506
Forks
138
Avg merge
3h 6m
Merged PRs (30d)
48

Description

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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.