Skip to content

Commit 8e5ce5a

Browse files
committed
Use explicity imports in readme and collapse sections (closes #316)
1 parent ec06d64 commit 8e5ce5a

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

README.md

+30-9
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,50 @@ from the parameters using Kotlin runtime type information.
4343
To use, just register the Kotlin module with your ObjectMapper instance:
4444

4545
```kotlin
46-
val mapper = ObjectMapper().registerModule(KotlinModule())
47-
// or with 2.10 and later
48-
val mapper = JsonMapper.builder().addModule(KotlinModule()).build()
49-
// or with 2.12 and later
46+
// With Jackson 2.12 and later
47+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
48+
...
49+
val mapper = jacksonObjectMapper()
50+
// or
51+
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
52+
...
53+
val mapper = ObjectMapper().registerKotlinModule()
54+
// or
55+
import com.fasterxml.jackson.module.kotlin.jsonMapper
56+
import com.fasterxml.jackson.module.kotlin.kotlinModule
57+
...
5058
val mapper = jsonMapper {
5159
addModule(kotlinModule())
5260
}
53-
5461
```
5562

56-
or with the extension functions imported from `import com.fasterxml.jackson.module.kotlin.*`, one of:
63+
<details>
64+
<summary>Jackson versions prior to 2.10–2.11</summary>
5765

5866
```kotlin
59-
val mapper = jacksonObjectMapper()
67+
import com.fasterxml.jackson.databind.json.JsonMapper
68+
import com.fasterxml.jackson.module.kotlin.KotlinModule
69+
...
70+
val mapper = JsonMapper.builder().addModule(KotlinModule()).build()
6071
```
72+
</details>
73+
74+
75+
<details>
76+
<summary>Jackson versions prior to 2.10</summary>
6177

6278
```kotlin
63-
val mapper = ObjectMapper().registerKotlinModule()
79+
import com.fasterxml.jackson.databind.ObjectMapper
80+
import com.fasterxml.jackson.module.kotlin.KotlinModule
81+
...
82+
val mapper = ObjectMapper().registerModule(KotlinModule())
6483
```
84+
</details>
6585

6686
A simple data class example:
6787
```kotlin
68-
import com.fasterxml.jackson.module.kotlin.*
88+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
89+
import com.fasterxml.jackson.module.kotlin.readValue
6990

7091
data class MyStateObject(val name: String, val age: Int)
7192

0 commit comments

Comments
 (0)