Skip to content

Commit c53e606

Browse files
authored
Merge pull request #741 from k163377/register-kotlin-module
Changed to allow KotlinFeature to be set in the function that registers a KotlinModule
2 parents 6883c16 + 20a5d5c commit c53e606

File tree

4 files changed

+17
-26
lines changed

4 files changed

+17
-26
lines changed

README.md

+2-22
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,8 @@ val mapper = jsonMapper {
5555
}
5656
```
5757

58-
<details>
59-
<summary>Jackson versions prior to 2.10–2.11</summary>
60-
61-
```kotlin
62-
import com.fasterxml.jackson.databind.json.JsonMapper
63-
import com.fasterxml.jackson.module.kotlin.KotlinModule
64-
...
65-
val mapper = JsonMapper.builder().addModule(KotlinModule()).build()
66-
```
67-
</details>
68-
69-
70-
<details>
71-
<summary>Jackson versions prior to 2.10</summary>
72-
73-
```kotlin
74-
import com.fasterxml.jackson.databind.ObjectMapper
75-
import com.fasterxml.jackson.module.kotlin.KotlinModule
76-
...
77-
val mapper = ObjectMapper().registerModule(KotlinModule())
78-
```
79-
</details>
58+
In 2.17 and later, the `jacksonObjectMapper {}` and `registerKotlinModule {}` lambdas allow configuration for `KotlinModule`.
59+
See [#Configuration](#Configuration) for details on the available configuration items.
8060

8161
A simple data class example:
8262
```kotlin

release-notes/CREDITS-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Contributors:
1818
# 2.17.0 (not yet released)
1919

2020
WrongWrong (@k163377)
21+
* #741: Changed to allow KotlinFeature to be set in the function that registers a KotlinModule.
2122
* #740: Reduce conversion cache from Executable to KFunction.
2223
* #738: Fix JacksonInject priority.
2324
* #732: SequenceSerializer removed.

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Co-maintainers:
1818

1919
2.17.0 (not yet released)
2020

21+
#741: Changed to allow KotlinFeature to be set in the function that registers a KotlinModule.
22+
The `jacksonObjectMapper {}` and `registerKotlinModule {}` lambdas allow configuration for KotlinModule.
2123
#740: Reduce conversion cache from Executable to KFunction.
2224
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.
2325
#738: JacksonInject is now preferred over the default argument(fixes #722).

src/main/kotlin/com/fasterxml/jackson/module/kotlin/Extensions.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,18 @@ fun jsonMapper(initializer: JsonMapper.Builder.() -> Unit = {}): JsonMapper {
3535
return builder.build()
3636
}
3737

38-
fun jacksonObjectMapper(): ObjectMapper = jsonMapper { addModule(kotlinModule()) }
39-
fun jacksonMapperBuilder(): JsonMapper.Builder = JsonMapper.builder().addModule(kotlinModule())
40-
41-
fun ObjectMapper.registerKotlinModule(): ObjectMapper = this.registerModule(kotlinModule())
38+
// region: JvmOverloads is set for bytecode compatibility for versions below 2.17.
39+
@JvmOverloads
40+
fun jacksonObjectMapper(initializer: KotlinModule.Builder.() -> Unit = {}): ObjectMapper =
41+
jsonMapper { addModule(kotlinModule(initializer)) }
42+
@JvmOverloads
43+
fun jacksonMapperBuilder(initializer: KotlinModule.Builder.() -> Unit = {}): JsonMapper.Builder =
44+
JsonMapper.builder().addModule(kotlinModule(initializer))
45+
46+
@JvmOverloads
47+
fun ObjectMapper.registerKotlinModule(initializer: KotlinModule.Builder.() -> Unit = {}): ObjectMapper =
48+
this.registerModule(kotlinModule(initializer))
49+
// endregion
4250

4351
inline fun <reified T> jacksonTypeRef(): TypeReference<T> = object: TypeReference<T>() {}
4452

0 commit comments

Comments
 (0)