Skip to content

Commit 7a19bc6

Browse files
authored
Merge pull request #388 from hiddewie/github-308-2.12
(#308) Add test for JsonProperty hiding
2 parents 9388da4 + 6b82691 commit 7a19bc6

File tree

1 file changed

+35
-0
lines changed
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
5+
import com.fasterxml.jackson.annotation.JsonProperty
6+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7+
import com.fasterxml.jackson.module.kotlin.readValue
8+
import org.junit.Test
9+
import kotlin.test.assertEquals
10+
import kotlin.test.assertNotNull
11+
import kotlin.test.assertNull
12+
13+
class Github308 {
14+
15+
@JsonIgnoreProperties(ignoreUnknown = true)
16+
data class TestDto(
17+
@JsonIgnore
18+
var id: Long? = null,
19+
var cityId: Int? = null
20+
) {
21+
@JsonProperty("id")
22+
private fun unpackId(idObj: Int?) {
23+
cityId = idObj
24+
}
25+
}
26+
27+
@Test
28+
fun createTestDto() {
29+
val dto: TestDto = jacksonObjectMapper().readValue("""{"id":12345}""")
30+
31+
assertNotNull(dto)
32+
assertNull(dto.id)
33+
assertEquals(dto.cityId, 12345)
34+
}
35+
}

0 commit comments

Comments
 (0)