diff --git a/README.md b/README.md index 9187f272..67c531e4 100644 --- a/README.md +++ b/README.md @@ -55,28 +55,8 @@ val mapper = jsonMapper { } ``` -
- Jackson versions prior to 2.10–2.11 - -```kotlin -import com.fasterxml.jackson.databind.json.JsonMapper -import com.fasterxml.jackson.module.kotlin.KotlinModule -... -val mapper = JsonMapper.builder().addModule(KotlinModule()).build() -``` -
- - -
- Jackson versions prior to 2.10 - -```kotlin -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.KotlinModule -... -val mapper = ObjectMapper().registerModule(KotlinModule()) -``` -
+In 2.17 and later, the `jacksonObjectMapper {}` and `registerKotlinModule {}` lambdas allow configuration for `KotlinModule`. +See [#Configuration](#Configuration) for details on the available configuration items. A simple data class example: ```kotlin diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 30a045ad..add6d3d2 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -18,6 +18,7 @@ Contributors: # 2.17.0 (not yet released) WrongWrong (@k163377) +* #741: Changed to allow KotlinFeature to be set in the function that registers a KotlinModule. * #740: Reduce conversion cache from Executable to KFunction. * #738: Fix JacksonInject priority. * #732: SequenceSerializer removed. diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 245c49ea..35f1d542 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,8 @@ Co-maintainers: 2.17.0 (not yet released) +#741: Changed to allow KotlinFeature to be set in the function that registers a KotlinModule. + The `jacksonObjectMapper {}` and `registerKotlinModule {}` lambdas allow configuration for KotlinModule. #740: Reduce conversion cache from Executable to KFunction. This will reduce memory usage efficiency and total memory consumption, but may result in a minor performance degradation in use cases where a large number of factory functions are used as JsonCreator. #738: JacksonInject is now preferred over the default argument(fixes #722). diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt index 7ccf411c..32f21eca 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt @@ -35,10 +35,18 @@ fun jsonMapper(initializer: JsonMapper.Builder.() -> Unit = {}): JsonMapper { return builder.build() } -fun jacksonObjectMapper(): ObjectMapper = jsonMapper { addModule(kotlinModule()) } -fun jacksonMapperBuilder(): JsonMapper.Builder = JsonMapper.builder().addModule(kotlinModule()) - -fun ObjectMapper.registerKotlinModule(): ObjectMapper = this.registerModule(kotlinModule()) +// region: JvmOverloads is set for bytecode compatibility for versions below 2.17. +@JvmOverloads +fun jacksonObjectMapper(initializer: KotlinModule.Builder.() -> Unit = {}): ObjectMapper = + jsonMapper { addModule(kotlinModule(initializer)) } +@JvmOverloads +fun jacksonMapperBuilder(initializer: KotlinModule.Builder.() -> Unit = {}): JsonMapper.Builder = + JsonMapper.builder().addModule(kotlinModule(initializer)) + +@JvmOverloads +fun ObjectMapper.registerKotlinModule(initializer: KotlinModule.Builder.() -> Unit = {}): ObjectMapper = + this.registerModule(kotlinModule(initializer)) +// endregion inline fun jacksonTypeRef(): TypeReference = object: TypeReference() {}