1
+ package com.fasterxml.jackson.module.kotlin.test.github.failing
2
+
3
+ import com.fasterxml.jackson.annotation.JsonInclude
4
+ import com.fasterxml.jackson.annotation.JsonProperty
5
+ import com.fasterxml.jackson.databind.MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
6
+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7
+ import org.junit.Ignore
8
+ import org.junit.Test
9
+ import kotlin.test.assertEquals
10
+
11
+ /* *
12
+ * Fields named "is…" are only serialized if they are Boolean
13
+ */
14
+ class TestGitHub337 {
15
+ private val mapper = jacksonObjectMapper()
16
+ .setSerializationInclusion(JsonInclude .Include .ALWAYS )
17
+ .configure(SORT_PROPERTIES_ALPHABETICALLY , true )
18
+ private val writer = mapper.writerWithDefaultPrettyPrinter()
19
+
20
+ @Test
21
+ @Ignore
22
+ fun test_ClassWithIsFields () {
23
+ data class ClassWithIsFields (
24
+ val isBooleanField : Boolean ,
25
+ val isIntField : Int
26
+ )
27
+
28
+ val problematic = ClassWithIsFields (true , 9 )
29
+ val expected = """
30
+ {
31
+ "isBooleanField" : true,
32
+ "isIntField" : 9
33
+ }""" .trimIndent()
34
+ assertEquals(expected, writer.writeValueAsString(problematic))
35
+ }
36
+
37
+ @Test
38
+ @Ignore
39
+ fun test_AnnotatedClassWithIsFields () {
40
+ data class ClassWithIsFields (
41
+ @JsonProperty(" isBooleanField" ) val isBooleanField : Boolean ,
42
+ @JsonProperty(" isIntField" ) val isIntField : Int
43
+ )
44
+
45
+ val problematic = ClassWithIsFields (true , 9 )
46
+ val expected = """
47
+ {
48
+ "isBooleanField" : true,
49
+ "isIntField" : 9
50
+ }""" .trimIndent()
51
+ assertEquals(expected, writer.writeValueAsString(problematic))
52
+ }
53
+
54
+ @Test
55
+ fun test_AnnotatedGetClassWithIsFields () {
56
+ data class ClassWithIsFields (
57
+ @JsonProperty(" isBooleanField" ) val isBooleanField : Boolean ,
58
+ @get:JsonProperty("isIntField") val isIntField : Int
59
+ )
60
+
61
+ val problematic = ClassWithIsFields (true , 9 )
62
+ val expected = """
63
+ {
64
+ "isBooleanField" : true,
65
+ "isIntField" : 9
66
+ }""" .trimIndent()
67
+ assertEquals(expected, writer.writeValueAsString(problematic))
68
+ }
69
+ }
0 commit comments