@@ -8,14 +8,14 @@ import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
8
8
import com.fasterxml.jackson.module.kotlin.KotlinFeature.StrictNullChecks
9
9
import com.fasterxml.jackson.module.kotlin.KotlinFeature.KotlinPropertyNameAsImplicitName
10
10
import com.fasterxml.jackson.module.kotlin.KotlinFeature.UseJavaDurationConversion
11
- import com.fasterxml.jackson.module.kotlin.SingletonSupport.CANONICALIZE
12
- import com.fasterxml.jackson.module.kotlin.SingletonSupport.DISABLED
13
11
import java.util.*
14
12
import kotlin.reflect.KClass
15
13
16
14
fun Class <* >.isKotlinClass (): Boolean = this .isAnnotationPresent(Metadata ::class .java)
17
15
18
16
/* *
17
+ * @constructor To avoid binary compatibility issues, the primary constructor is not published.
18
+ * Please use KotlinModule.Builder or extensions that use it.
19
19
* @property reflectionCacheSize Default: 512. Size, in items, of the caches used for mapping objects.
20
20
* @property nullToEmptyCollection Default: false. Whether to deserialize null values for collection properties as
21
21
* empty collections.
@@ -36,43 +36,32 @@ fun Class<*>.isKotlinClass(): Boolean = this.isAnnotationPresent(Metadata::class
36
36
* @property useJavaDurationConversion Default: false. Whether to use [java.time.Duration] as a bridge for [kotlin.time.Duration].
37
37
* This allows use Kotlin Duration type with [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule].
38
38
*/
39
- class KotlinModule @Deprecated(
40
- level = DeprecationLevel .ERROR ,
41
- message = " Use KotlinModule.Builder instead of named constructor parameters. It will be HIDDEN at 2.18." ,
42
- replaceWith = ReplaceWith (
43
- """ KotlinModule.Builder()
44
- .withReflectionCacheSize(reflectionCacheSize)
45
- .configure(KotlinFeature.NullToEmptyCollection, nullToEmptyCollection)
46
- .configure(KotlinFeature.NullToEmptyMap, nullToEmptyMap)
47
- .configure(KotlinFeature.NullIsSameAsDefault, nullIsSameAsDefault)
48
- .configure(KotlinFeature.SingletonSupport, singletonSupport)
49
- .configure(KotlinFeature.StrictNullChecks, strictNullChecks)
50
- .build()""" ,
51
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
52
- )
53
- ) constructor(
39
+ class KotlinModule private constructor(
54
40
val reflectionCacheSize : Int = Builder .DEFAULT_CACHE_SIZE ,
55
41
val nullToEmptyCollection : Boolean = NullToEmptyCollection .enabledByDefault,
56
42
val nullToEmptyMap : Boolean = NullToEmptyMap .enabledByDefault,
57
43
val nullIsSameAsDefault : Boolean = NullIsSameAsDefault .enabledByDefault,
58
44
@property:Deprecated(
59
- level = DeprecationLevel .WARNING ,
45
+ level = DeprecationLevel .ERROR ,
60
46
message = "The return value will be Boolean in 2.19. Until then, use enabledSingletonSupport.",
61
47
replaceWith = ReplaceWith ("enabledSingletonSupport")
62
48
)
63
- val singletonSupport : SingletonSupport = DISABLED ,
49
+ @Suppress(" DEPRECATION_ERROR" )
50
+ val singletonSupport : SingletonSupport = SingletonSupport .DISABLED ,
64
51
val strictNullChecks : Boolean = StrictNullChecks .enabledByDefault,
65
52
@Deprecated(
66
- level = DeprecationLevel .WARNING ,
53
+ level = DeprecationLevel .ERROR ,
67
54
message = " There was a discrepancy between the property name and the Feature name." +
68
55
" To migrate to the correct property name, it will be ERROR in 2.18 and removed in 2.19." ,
69
56
replaceWith = ReplaceWith (" kotlinPropertyNameAsImplicitName" )
70
57
)
71
58
val useKotlinPropertyNameForGetter : Boolean = KotlinPropertyNameAsImplicitName .enabledByDefault,
72
59
val useJavaDurationConversion : Boolean = UseJavaDurationConversion .enabledByDefault,
73
60
) : SimpleModule(KotlinModule : :class.java.name, PackageVersion .VERSION ) {
61
+ @Suppress(" DEPRECATION_ERROR" )
74
62
val kotlinPropertyNameAsImplicitName: Boolean get() = useKotlinPropertyNameForGetter
75
- val enabledSingletonSupport: Boolean get() = singletonSupport == CANONICALIZE
63
+ @Suppress(" DEPRECATION_ERROR" )
64
+ val enabledSingletonSupport: Boolean get() = singletonSupport == SingletonSupport .CANONICALIZE
76
65
77
66
companion object {
78
67
// Increment when option is added
@@ -83,45 +72,17 @@ class KotlinModule @Deprecated(
83
72
level = DeprecationLevel .HIDDEN ,
84
73
message = " If you have no choice but to initialize KotlinModule from reflection, use this constructor."
85
74
)
86
- @Suppress(" DEPRECATION_ERROR" )
87
75
constructor () : this ()
88
76
89
- @Deprecated(level = DeprecationLevel .HIDDEN , message = " For ABI compatibility. It will be removed in 2.18." )
90
- constructor (
91
- reflectionCacheSize: Int ,
92
- nullToEmptyCollection: Boolean ,
93
- nullToEmptyMap: Boolean
94
- ) : this (
95
- Builder ()
96
- .withReflectionCacheSize(reflectionCacheSize)
97
- .configure(NullToEmptyCollection , nullToEmptyCollection)
98
- .configure(NullToEmptyMap , nullToEmptyMap)
99
- .disable(NullIsSameAsDefault )
100
- )
101
-
102
- @Deprecated(level = DeprecationLevel .HIDDEN , message = " For ABI compatibility. It will be removed in 2.18." )
103
- constructor (
104
- reflectionCacheSize: Int ,
105
- nullToEmptyCollection: Boolean ,
106
- nullToEmptyMap: Boolean ,
107
- nullIsSameAsDefault: Boolean
108
- ) : this (
109
- Builder ()
110
- .withReflectionCacheSize(reflectionCacheSize)
111
- .configure(NullToEmptyCollection , nullToEmptyCollection)
112
- .configure(NullToEmptyMap , nullToEmptyMap)
113
- .configure(NullIsSameAsDefault , nullIsSameAsDefault)
114
- )
115
-
116
- @Suppress(" DEPRECATION_ERROR" )
117
77
private constructor (builder: Builder ) : this (
118
78
builder.reflectionCacheSize,
119
79
builder.isEnabled(NullToEmptyCollection ),
120
80
builder.isEnabled(NullToEmptyMap ),
121
81
builder.isEnabled(NullIsSameAsDefault ),
82
+ @Suppress(" DEPRECATION_ERROR" )
122
83
when {
123
- builder.isEnabled(KotlinFeature .SingletonSupport ) -> CANONICALIZE
124
- else -> DISABLED
84
+ builder.isEnabled(KotlinFeature .SingletonSupport ) -> SingletonSupport . CANONICALIZE
85
+ else -> SingletonSupport . DISABLED
125
86
},
126
87
builder.isEnabled(StrictNullChecks ),
127
88
builder.isEnabled(KotlinPropertyNameAsImplicitName ),
@@ -141,11 +102,8 @@ class KotlinModule @Deprecated(
141
102
142
103
context.addValueInstantiators(KotlinInstantiators (cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, strictNullChecks))
143
104
144
- when (singletonSupport) {
145
- DISABLED -> Unit
146
- CANONICALIZE -> {
147
- context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier )
148
- }
105
+ if (enabledSingletonSupport) {
106
+ context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier )
149
107
}
150
108
151
109
context.insertAnnotationIntrospector(KotlinAnnotationIntrospector (
@@ -160,7 +118,7 @@ class KotlinModule @Deprecated(
160
118
KotlinNamesAnnotationIntrospector (
161
119
cache,
162
120
ignoredClassesForImplyingJsonCreator,
163
- useKotlinPropertyNameForGetter )
121
+ kotlinPropertyNameAsImplicitName )
164
122
)
165
123
166
124
context.addDeserializers(KotlinDeserializers (cache, useJavaDurationConversion))
@@ -203,130 +161,6 @@ class KotlinModule @Deprecated(
203
161
fun isEnabled (feature : KotlinFeature ): Boolean =
204
162
bitSet.intersects(feature.bitSet)
205
163
206
- @Deprecated(
207
- level = DeprecationLevel .ERROR ,
208
- message = " Deprecated, use withReflectionCacheSize(reflectionCacheSize) instead. It will be removed in 2.18." ,
209
- replaceWith = ReplaceWith (" withReflectionCacheSize(reflectionCacheSize)" )
210
- )
211
- fun reflectionCacheSize (reflectionCacheSize : Int ): Builder =
212
- withReflectionCacheSize(reflectionCacheSize)
213
-
214
- @Deprecated(
215
- level = DeprecationLevel .ERROR ,
216
- message = " Deprecated, use isEnabled(NullToEmptyCollection) instead. It will be removed in 2.18." ,
217
- replaceWith = ReplaceWith (
218
- " isEnabled(KotlinFeature.NullToEmptyCollection)" ,
219
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
220
- )
221
- )
222
- fun getNullToEmptyCollection (): Boolean =
223
- isEnabled(NullToEmptyCollection )
224
-
225
- @Deprecated(
226
- level = DeprecationLevel .ERROR ,
227
- message = " Deprecated, use configure(NullToEmptyCollection, enabled) instead. It will be removed in 2.18." ,
228
- replaceWith = ReplaceWith (
229
- " configure(KotlinFeature.NullToEmptyCollection, nullToEmptyCollection)" ,
230
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
231
- )
232
- )
233
- fun nullToEmptyCollection (nullToEmptyCollection : Boolean ): Builder =
234
- configure(NullToEmptyCollection , nullToEmptyCollection)
235
-
236
- @Deprecated(
237
- level = DeprecationLevel .ERROR ,
238
- message = " Deprecated, use isEnabled(NullToEmptyMap) instead. It will be removed in 2.18." ,
239
- replaceWith = ReplaceWith (
240
- " isEnabled(KotlinFeature.NullToEmptyMap)" ,
241
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
242
- )
243
- )
244
- fun getNullToEmptyMap (): Boolean =
245
- isEnabled(NullToEmptyMap )
246
-
247
- @Deprecated(
248
- level = DeprecationLevel .ERROR ,
249
- message = " Deprecated, use configure(NullToEmptyMap, enabled) instead. It will be removed in 2.18." ,
250
- replaceWith = ReplaceWith (
251
- " configure(KotlinFeature.NullToEmptyMap, nullToEmptyMap)" ,
252
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
253
- )
254
- )
255
- fun nullToEmptyMap (nullToEmptyMap : Boolean ): Builder =
256
- configure(NullToEmptyMap , nullToEmptyMap)
257
-
258
- @Deprecated(
259
- level = DeprecationLevel .ERROR ,
260
- message = " Deprecated, use isEnabled(NullIsSameAsDefault) instead. It will be removed in 2.18." ,
261
- replaceWith = ReplaceWith (
262
- " isEnabled(KotlinFeature.NullIsSameAsDefault)" ,
263
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
264
- )
265
- )
266
- fun getNullIsSameAsDefault (): Boolean =
267
- isEnabled(NullIsSameAsDefault )
268
-
269
- @Deprecated(
270
- level = DeprecationLevel .ERROR ,
271
- message = " Deprecated, use configure(NullIsSameAsDefault, enabled) instead. It will be removed in 2.18." ,
272
- replaceWith = ReplaceWith (
273
- " configure(KotlinFeature.NullIsSameAsDefault, nullIsSameAsDefault)" ,
274
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
275
- )
276
- )
277
- fun nullIsSameAsDefault (nullIsSameAsDefault : Boolean ): Builder =
278
- configure(NullIsSameAsDefault , nullIsSameAsDefault)
279
-
280
- @Deprecated(
281
- level = DeprecationLevel .ERROR ,
282
- message = " Deprecated, use isEnabled(SingletonSupport) instead. It will be removed in 2.18." ,
283
- replaceWith = ReplaceWith (
284
- " isEnabled(KotlinFeature.SingletonSupport)" ,
285
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
286
- )
287
- )
288
- fun getSingletonSupport (): SingletonSupport =
289
- when {
290
- isEnabled(KotlinFeature .SingletonSupport ) -> CANONICALIZE
291
- else -> DISABLED
292
- }
293
-
294
- @Deprecated(
295
- level = DeprecationLevel .ERROR ,
296
- message = " Deprecated, use configure(SingletonSupport, enabled) instead. It will be removed in 2.18." ,
297
- replaceWith = ReplaceWith (
298
- " configure(KotlinFeature.SingletonSupport, singletonSupport)" ,
299
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
300
- )
301
- )
302
- fun singletonSupport (singletonSupport : SingletonSupport ): Builder =
303
- when (singletonSupport) {
304
- CANONICALIZE -> enable(KotlinFeature .SingletonSupport )
305
- else -> disable(KotlinFeature .SingletonSupport )
306
- }
307
-
308
- @Deprecated(
309
- level = DeprecationLevel .ERROR ,
310
- message = " Deprecated, use isEnabled(StrictNullChecks) instead. It will be removed in 2.18." ,
311
- replaceWith = ReplaceWith (
312
- " isEnabled(KotlinFeature.StrictNullChecks)" ,
313
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
314
- )
315
- )
316
- fun getStrictNullChecks (): Boolean =
317
- isEnabled(StrictNullChecks )
318
-
319
- @Deprecated(
320
- level = DeprecationLevel .ERROR ,
321
- message = " Deprecated, use configure(StrictNullChecks, enabled) instead. It will be removed in 2.18." ,
322
- replaceWith = ReplaceWith (
323
- " configure(KotlinFeature.StrictNullChecks, strictNullChecks)" ,
324
- " com.fasterxml.jackson.module.kotlin.KotlinFeature"
325
- )
326
- )
327
- fun strictNullChecks (strictNullChecks : Boolean ): Builder =
328
- configure(StrictNullChecks , strictNullChecks)
329
-
330
164
fun build (): KotlinModule =
331
165
KotlinModule (this )
332
166
}
0 commit comments