File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.fasterxml.jackson.module.kotlin.test.github
2+
3+ import com.fasterxml.jackson.databind.BeanDescription
4+ import com.fasterxml.jackson.databind.ObjectMapper
5+ import com.fasterxml.jackson.module.kotlin.KotlinFeature
6+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
7+ import org.junit.jupiter.api.Assertions.assertTrue
8+ import kotlin.test.Test
9+
10+ class GitHub922 {
11+ private inline fun <reified T : Any > ObjectMapper.introspectSerialization (): BeanDescription =
12+ serializationConfig.introspect(serializationConfig.constructType(T ::class .java))
13+
14+ private inline fun <reified T : Any > ObjectMapper.introspectDeserialization (): BeanDescription =
15+ deserializationConfig.introspect(deserializationConfig.constructType(T ::class .java))
16+
17+ private fun BeanDescription.isRequired (propertyName : String ): Boolean =
18+ this .findProperties().first { it.name == propertyName }.isRequired
19+
20+ @Test
21+ fun `nullToEmpty does not override specification by Java annotation` () {
22+ val mapper = jacksonObjectMapper {
23+ enable(KotlinFeature .NullToEmptyCollection )
24+ enable(KotlinFeature .NullToEmptyMap )
25+ }
26+
27+ val desc = mapper.introspectDeserialization<GitHub922RequiredCollectionsDtoJava >()
28+
29+ assertTrue(desc.isRequired(" list" ))
30+ assertTrue(desc.isRequired(" map" ))
31+ }
32+ }
Original file line number Diff line number Diff line change 1+ package com .fasterxml .jackson .module .kotlin .test .github ;
2+
3+ import com .fasterxml .jackson .annotation .JsonCreator ;
4+ import com .fasterxml .jackson .annotation .JsonProperty ;
5+
6+ import java .util .List ;
7+ import java .util .Map ;
8+
9+ public class GitHub922RequiredCollectionsDtoJava {
10+ private final List <String > list ;
11+ private final Map <String , String > map ;
12+
13+ @ JsonCreator
14+ public GitHub922RequiredCollectionsDtoJava (
15+ @ JsonProperty (value = "list" , required = true ) List <String > list ,
16+ @ JsonProperty (value = "map" , required = true ) Map <String , String > map
17+ ) {
18+ this .list = list ;
19+ this .map = map ;
20+ }
21+
22+ public List <String > getList () {
23+ return list ;
24+ }
25+
26+ public Map <String , String > getMap () {
27+ return map ;
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments