|
| 1 | +package tools.jackson.module.kotlin.test.github |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonProperty |
| 4 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 5 | +import org.junit.jupiter.api.Test |
| 6 | +import tools.jackson.databind.BeanDescription |
| 7 | +import tools.jackson.databind.ObjectMapper |
| 8 | +import tools.jackson.module.kotlin.defaultMapper |
| 9 | +import tools.jackson.module.kotlin.jacksonObjectMapper |
| 10 | + |
| 11 | +class GitHub668 { |
| 12 | + private inline fun <reified T : Any> ObjectMapper.introspectDeserialization(): BeanDescription = |
| 13 | + _deserializationContext().introspectBeanDescription(_deserializationContext().constructType(T::class.java)) |
| 14 | + |
| 15 | + private fun BeanDescription.isRequired(propertyName: String): Boolean = |
| 16 | + this.findProperties().find { it.name == propertyName }?.isRequired ?: false |
| 17 | + |
| 18 | + data class AffectByAccessor( |
| 19 | + @get:JsonProperty(required = true) |
| 20 | + var a: String?, |
| 21 | + @field:JsonProperty(required = true) |
| 22 | + var b: String?, |
| 23 | + @set:JsonProperty(required = true) |
| 24 | + var c: String? |
| 25 | + ) { |
| 26 | + @get:JsonProperty(required = true) |
| 27 | + var x: String? = null |
| 28 | + @field:JsonProperty(required = true) |
| 29 | + var y: String? = null |
| 30 | + @JvmField |
| 31 | + @field:JsonProperty(required = true) |
| 32 | + var z: String? = null |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + fun affectByAccessorTestDeser() { |
| 37 | + val desc = defaultMapper.introspectDeserialization<AffectByAccessor>() |
| 38 | + |
| 39 | + assertTrue(desc.isRequired("a")) |
| 40 | + assertTrue(desc.isRequired("b")) |
| 41 | + assertTrue(desc.isRequired("c")) |
| 42 | + assertTrue(desc.isRequired("x")) |
| 43 | + assertTrue(desc.isRequired("y")) |
| 44 | + assertTrue(desc.isRequired("z")) |
| 45 | + } |
| 46 | +} |
0 commit comments