Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ScalaAnnotationIntrospectorInstance(scalaAnnotationIntrospectorModule: Sca
override def findSerializationSortAlphabetically(config: MapperConfig[_], ann: Annotated): java.lang.Boolean = {
ann match {
case ac: AnnotatedClass if scalaAnnotationIntrospectorModule.isMaybeScalaBeanType(ac.getAnnotated) =>
java.lang.Boolean.FALSE
!config.isEnabled(MapperFeature.SORT_CREATOR_PROPERTIES_FIRST)
case _ => None.orNull
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tools.jackson.module.scala.ser
import com.fasterxml.jackson.annotation.JsonProperty.Access
import com.fasterxml.jackson.annotation._
import tools.jackson.databind.cfg.MutableConfigOverride
import tools.jackson.databind.{ObjectMapper, PropertyNamingStrategies}
import tools.jackson.databind.{MapperFeature, ObjectMapper, PropertyNamingStrategies}
import tools.jackson.module.scala.DefaultScalaModule

import scala.beans.BeanProperty
Expand Down Expand Up @@ -66,6 +66,7 @@ case class ClassWithOnlyUnitField(field: Unit)

object CaseClassSerializerTest {
case class BigDecimalHolder(bigDecimal: BigDecimal)
case class ClassWithUnorderedFields(f3: Int = 3, f2: Int = 2, f0: Int = 0, f1: Int = 1)
}

class CaseClassSerializerTest extends SerializerTest {
Expand Down Expand Up @@ -229,4 +230,12 @@ class CaseClassSerializerTest extends SerializerTest {
(c: MutableConfigOverride) => c.setFormat(JsonFormat.Value.forShape(JsonFormat.Shape.STRING)))
serialize(BigDecimalHolder(BigDecimal("123.456")), builder.build()) shouldEqual """{"bigDecimal":"123.456"}"""
}

it should "sort properties of the case class" in {
val mapper = newBuilder
.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
.disable(MapperFeature.SORT_CREATOR_PROPERTIES_FIRST)
.build()
serialize(ClassWithUnorderedFields(), mapper) shouldEqual """{"f0":0,"f1":1,"f2":2,"f3":3}"""
}
}