@@ -39,7 +39,9 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI
3939 // For Scala, we want to use the declared order of the fields in the class
4040 override def findSerializationSortAlphabetically (ann : Annotated ): java.lang.Boolean = {
4141 ann match {
42- case ac : AnnotatedClass if isMaybeScalaBeanType(ac.getAnnotated) =>
42+ case ac : AnnotatedClass if
43+ ScalaAnnotationIntrospectorModule .isCaseClassDefaultSerializationOrderBasedOnDeclaredParamOrder &&
44+ isMaybeScalaBeanType(ac.getAnnotated) =>
4345 val annotation = _findAnnotation(ac, classOf [JsonPropertyOrder ])
4446 if (annotation != null ) {
4547 // delegate to JacksonAnnotationIntrospector
@@ -468,7 +470,27 @@ trait ScalaAnnotationIntrospectorModule extends JacksonModule {
468470 def shouldSupportScala3Classes (): Boolean = _shouldSupportScala3Classes
469471}
470472
471- object ScalaAnnotationIntrospectorModule extends ScalaAnnotationIntrospectorModule
473+ object ScalaAnnotationIntrospectorModule extends ScalaAnnotationIntrospectorModule {
474+ private var caseClassDefaultOrderBasedOnDeclaredParamOrder = true
475+
476+ /**
477+ * @return Whether to default the serialization order of Case Class params to the defined order in the class.
478+ * This should be set to false if you want to enable <code>MapperFeature.SORT_PROPERTIES_ALPHABETICALLY</code>.
479+ * This is not needed in Jackson 3.
480+ * @since 2.20.1
481+ */
482+ def isCaseClassDefaultSerializationOrderBasedOnDeclaredParamOrder : Boolean =
483+ caseClassDefaultOrderBasedOnDeclaredParamOrder
484+
485+ /**
486+ * @param flag Whether to default the serialization order of Case Class params to the defined order in the class.
487+ * This should be set to false if you want to enable <code>MapperFeature.SORT_PROPERTIES_ALPHABETICALLY</code>.
488+ * This is not needed in Jackson 3.
489+ * @since 2.20.1
490+ */
491+ def setCaseClassDefaultSerializationOrderBasedOnDeclaredParamOrder (flag : Boolean ): Unit =
492+ this .caseClassDefaultOrderBasedOnDeclaredParamOrder = flag
493+ }
472494
473495private case class WrappedCreatorProperty (creatorProperty : CreatorProperty , refHolder : ClassHolder )
474496 extends CreatorProperty (creatorProperty, creatorProperty.getFullName) {
0 commit comments