1
1
package com.fasterxml.jackson.module.kotlin.test.github
2
2
3
3
import com.fasterxml.jackson.annotation.JsonProperty
4
+ import com.fasterxml.jackson.databind.MapperFeature
5
+ import com.fasterxml.jackson.databind.SerializationFeature
4
6
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
5
7
import kotlin.test.assertEquals
6
8
7
9
class TestGithub52 {
8
10
class Test (
9
- // This gets serialized as "is_lol", as expected. No issues here.
10
- @JsonProperty(" is_lol " )
11
- val lol : String = " sdf " ,
12
-
13
- // This gets serialized as "bar", even though we asked for "is_bar". This is an issue.
14
- @JsonProperty( " is_bar " )
15
- val bar : Boolean = true ,
16
-
17
- @JsonProperty(" is_bar2 " )
18
- val isBar2 : Boolean = true ) {
19
-
20
- // This gets serialized as both "foo" and " is_foo", although we only asked for "is_foo". Also an issue.
11
+ // Should only be serialized as "is_bar"
12
+ @JsonProperty(" is_bar " )
13
+ val bar : Boolean = true ,
14
+
15
+ @JsonProperty( " is_bar2 " )
16
+ val isBar2 : Boolean = true ,
17
+
18
+ // This gets serialized as "is_lol", as expected. No issues here.
19
+ @JsonProperty(" is_lol " )
20
+ val lol : String = " sdf "
21
+ ) {
22
+ // Should only be serialized as " is_foo"
21
23
@JsonProperty(" is_foo" )
22
24
val foo: Boolean = true
23
25
@@ -28,17 +30,19 @@ class TestGithub52 {
28
30
@org.junit.Test
29
31
fun testGithub52 () {
30
32
val mapper = jacksonObjectMapper()
33
+ .configure(SerializationFeature .INDENT_OUTPUT , true )
34
+ .configure(MapperFeature .SORT_PROPERTIES_ALPHABETICALLY , true )
31
35
32
36
val actual = mapper.writeValueAsString(Test ())
33
- val expected = """ {"is_lol":"sdf","is_bar":true,"is_bar2":true,"is_foo":true,"is_foo2":true} """
34
-
35
- // error
36
- // {"is_lol":"sdf" ,
37
- // "is_bar":true ,
38
- // "bar2 ":true, ... should be is_bar2
39
- // "foo2":true, ... should not be here
40
- // "is_foo":true,
41
- // "is_foo2":true}
37
+ val expected = """
38
+ {
39
+ "is_bar":true,
40
+ "is_bar2":true ,
41
+ "is_lol":"sdf" ,
42
+ "is_foo ":true,
43
+ "is_foo2":true
44
+ } """ .trimIndent()
45
+
42
46
assertEquals(expected, actual)
43
47
}
44
48
}
0 commit comments