File tree 4 files changed +14
-11
lines changed
main/scala/tools/jackson/module/scala/introspect
test/scala/tools/jackson/module/scala
4 files changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,15 @@ class ScalaAnnotationIntrospectorInstance(scalaAnnotationIntrospectorModule: Sca
38
38
}
39
39
}
40
40
41
+ // For Scala, we want to use the declared order of the fields in the class
42
+ override def findSerializationSortAlphabetically (config : MapperConfig [_], ann : Annotated ): java.lang.Boolean = {
43
+ ann match {
44
+ case ac : AnnotatedClass if scalaAnnotationIntrospectorModule.isMaybeScalaBeanType(ac.getAnnotated) =>
45
+ java.lang.Boolean .FALSE
46
+ case _ => None .orNull
47
+ }
48
+ }
49
+
41
50
override def findImplicitPropertyName (mapperConfig : MapperConfig [_], member : AnnotatedMember ): String = {
42
51
member match {
43
52
case af : AnnotatedField => fieldName(af).orNull
Original file line number Diff line number Diff line change @@ -136,8 +136,7 @@ class ClassTagExtensionsTest extends JacksonTest {
136
136
val result = mapper.writerWithView[PublicView ].writeValueAsString(instance)
137
137
result should equal(""" {"foo":"foo"}""" )
138
138
val resultInView = mapper.writerWithView[PrivateView ].writeValueAsString(instance)
139
- // JSON order for non-constructor params changed in Jackson 3 due to https://github.com/FasterXML/jackson-databind/pull/4572
140
- resultInView should equal(""" {"bar":42,"foo":"foo"}""" )
139
+ resultInView should equal(""" {"foo":"foo","bar":42}""" )
141
140
}
142
141
143
142
it should " produce writer with type" in {
Original file line number Diff line number Diff line change @@ -160,8 +160,7 @@ class CaseClassSerializerTest extends SerializerTest {
160
160
val bean = new NonCaseWithBeanProperty
161
161
bean.id = 1
162
162
bean.bar = " foo"
163
- // JSON order for non-constructor params changed in Jackson 3 due to https://github.com/FasterXML/jackson-databind/pull/4572
164
- serialize(bean) should equal( """ {"bar":"foo","id":1}""" )
163
+ serialize(bean) should equal( """ {"id":1,"bar":"foo"}""" )
165
164
}
166
165
167
166
it should " serialize a nested case class" in {
@@ -186,10 +185,7 @@ class CaseClassSerializerTest extends SerializerTest {
186
185
def isBoolean = boolean
187
186
}
188
187
val foo = new Foo (" str" , false )
189
- val mapper = newBuilder
190
- .disable(MapperFeature .SORT_PROPERTIES_ALPHABETICALLY )
191
- .build()
192
- mapper.writeValueAsString(foo) should equal (""" {"string":"str","boolean":false}""" )
188
+ serialize(foo) should equal (""" {"string":"str","boolean":false}""" )
193
189
}
194
190
195
191
it should " serialize java getters returning java collections" in {
Original file line number Diff line number Diff line change @@ -130,11 +130,10 @@ class OptionSerializerTest extends SerializerTest {
130
130
131
131
it should " support default typing" in {
132
132
case class User (name : String , email : Option [String ] = None )
133
- val mapper = newBuilder.disable(MapperFeature .SORT_PROPERTIES_ALPHABETICALLY ).build()
134
133
val user = User (" John Smith" , Some (" john.smith@unit.uk" ))
135
134
val expected = """ {"name":"John Smith","email":"john.smith@unit.uk"}"""
136
- mapper .writeValueAsString(user) shouldEqual expected
137
- val mapper2 = newBuilder.disable( MapperFeature . SORT_PROPERTIES_ALPHABETICALLY )
135
+ newMapper .writeValueAsString(user) shouldEqual expected
136
+ val mapper2 = newBuilder
138
137
.activateDefaultTyping(new DefaultBaseTypeLimitingValidator )
139
138
.build()
140
139
mapper2.writeValueAsString(user) shouldEqual expected
You can’t perform that action at this time.
0 commit comments