|
1 | 1 | package com.fasterxml.jackson.module.kotlin.test.github
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnore |
3 | 4 | import com.fasterxml.jackson.annotation.JsonProperty
|
4 |
| -import com.fasterxml.jackson.databind.MapperFeature |
5 |
| -import com.fasterxml.jackson.databind.SerializationFeature |
6 | 5 | import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
7 | 6 | import kotlin.test.assertEquals
|
8 | 7 |
|
9 | 8 | class TestGithub52 {
|
10 |
| - class Test( |
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" |
23 |
| - @JsonProperty("is_foo") |
24 |
| - val foo: Boolean = true |
25 |
| - |
26 |
| - @JsonProperty("is_foo2") |
27 |
| - val isFoo2: Boolean = true |
| 9 | + private val mapper = jacksonObjectMapper() |
| 10 | + |
| 11 | + @org.junit.Test |
| 12 | + fun testBooleanPropertyInConstructor() { |
| 13 | + data class BooleanPropertyInConstructor( |
| 14 | + @JsonProperty("is_bar") |
| 15 | + val bar: Boolean = true |
| 16 | + ) |
| 17 | + |
| 18 | + assertEquals("""{"is_bar":true}""", mapper.writeValueAsString(BooleanPropertyInConstructor())) |
| 19 | + } |
| 20 | + |
| 21 | + @org.junit.Test |
| 22 | + fun testIsPrefixedBooleanPropertyInConstructor() { |
| 23 | + data class IsPrefixedBooleanPropertyInConstructor( |
| 24 | + @JsonProperty("is_bar2") |
| 25 | + val isBar2: Boolean = true |
| 26 | + ) |
| 27 | + |
| 28 | + assertEquals("""{"is_bar2":true}""", mapper.writeValueAsString(IsPrefixedBooleanPropertyInConstructor())) |
| 29 | + } |
| 30 | + |
| 31 | + @org.junit.Test |
| 32 | + fun testIsPrefixedStringPropertyInConstructor() { |
| 33 | + data class IsPrefixedStringPropertyInConstructor( |
| 34 | + @JsonProperty("is_lol") |
| 35 | + val lol: String = "sdf" |
| 36 | + ) |
| 37 | + |
| 38 | + assertEquals("""{"is_lol":"sdf"}""", mapper.writeValueAsString(IsPrefixedStringPropertyInConstructor())) |
| 39 | + } |
| 40 | + |
| 41 | + @org.junit.Test |
| 42 | + fun testBooleanPropertyInBody() { |
| 43 | + data class BooleanPropertyInBody( |
| 44 | + @JsonIgnore val placeholder: String = "placeholder" |
| 45 | + ) { |
| 46 | + @JsonProperty("is_foo") |
| 47 | + val foo: Boolean = true |
| 48 | + } |
| 49 | + |
| 50 | + assertEquals("""{"is_foo":true}""", mapper.writeValueAsString(BooleanPropertyInBody())) |
28 | 51 | }
|
29 | 52 |
|
30 | 53 | @org.junit.Test
|
31 |
| - fun testGithub52() { |
32 |
| - val mapper = jacksonObjectMapper() |
33 |
| - .configure(SerializationFeature.INDENT_OUTPUT, true) |
34 |
| - .configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true) |
35 |
| - |
36 |
| - val actual = mapper.writeValueAsString(Test()) |
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 |
| - |
46 |
| - assertEquals(expected, actual) |
| 54 | + fun testIsPrefixedBooleanPropertyInBody() { |
| 55 | + data class IsPrefixedBooleanPropertyInBody( |
| 56 | + @JsonIgnore val placeholder: String = "placeholder" |
| 57 | + ) { |
| 58 | + @JsonProperty("is_foo2") |
| 59 | + val isFoo2: Boolean = true |
| 60 | + } |
| 61 | + |
| 62 | + assertEquals("""{"is_foo2":true}""", mapper.writeValueAsString(IsPrefixedBooleanPropertyInBody())) |
47 | 63 | }
|
48 | 64 | }
|
0 commit comments