@@ -32,28 +32,28 @@ fun Class<*>.isKotlinClass(): Boolean {
32
32
* (e.g. List<String>) may contain null values after deserialization. Enabling it
33
33
* protects against this but has significant performance impact.
34
34
*/
35
- class KotlinModule private constructor(
36
- val reflectionCacheSize : Int ,
37
- val nullToEmptyCollection : Boolean ,
38
- val nullToEmptyMap : Boolean ,
39
- val nullIsSameAsDefault : Boolean ,
40
- val singletonSupport : SingletonSupport ,
41
- val strictNullChecks : Boolean
35
+ class KotlinModule @Deprecated(level = DeprecationLevel . WARNING , message = " Use KotlinModule.Builder " ) constructor(
36
+ val reflectionCacheSize : Int = 512 ,
37
+ val nullToEmptyCollection : Boolean = false ,
38
+ val nullToEmptyMap : Boolean = false ,
39
+ val nullIsSameAsDefault : Boolean = false ,
40
+ val singletonSupport : SingletonSupport = DISABLED ,
41
+ val strictNullChecks : Boolean = false
42
42
) : SimpleModule(PackageVersion .VERSION ) {
43
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use KotlinModule.Builder " )
43
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " For ABI compatibility " )
44
44
constructor (
45
45
reflectionCacheSize: Int ,
46
46
nullToEmptyCollection: Boolean ,
47
47
nullToEmptyMap: Boolean
48
48
) : this (
49
49
Builder ()
50
50
.withReflectionCacheSize(reflectionCacheSize)
51
- .set (NullToEmptyCollection , nullToEmptyCollection)
52
- .set (NullToEmptyMap , nullToEmptyMap)
51
+ .configure (NullToEmptyCollection , nullToEmptyCollection)
52
+ .configure (NullToEmptyMap , nullToEmptyMap)
53
53
.disable(NullIsSameAsDefault )
54
54
)
55
55
56
- @Deprecated(level = DeprecationLevel .WARNING , message = " Use KotlinModule.Builder " )
56
+ @Deprecated(level = DeprecationLevel .HIDDEN , message = " For ABI compatibility " )
57
57
constructor (
58
58
reflectionCacheSize: Int ,
59
59
nullToEmptyCollection: Boolean ,
@@ -62,11 +62,12 @@ class KotlinModule private constructor(
62
62
) : this (
63
63
Builder ()
64
64
.withReflectionCacheSize(reflectionCacheSize)
65
- .set (NullToEmptyCollection , nullToEmptyCollection)
66
- .set (NullToEmptyMap , nullToEmptyMap)
67
- .set (NullIsSameAsDefault , nullIsSameAsDefault)
65
+ .configure (NullToEmptyCollection , nullToEmptyCollection)
66
+ .configure (NullToEmptyMap , nullToEmptyMap)
67
+ .configure (NullIsSameAsDefault , nullIsSameAsDefault)
68
68
)
69
69
70
+ @Suppress(" DEPRECATION" )
70
71
private constructor (builder: Builder ) : this (
71
72
builder.reflectionCacheSize,
72
73
builder.isEnabled(NullToEmptyCollection ),
@@ -125,7 +126,7 @@ class KotlinModule private constructor(
125
126
private set
126
127
127
128
private val bitSet: BitSet = 0 .toBitSet().apply {
128
- KotlinFeature .values().filter { it.enabledByDefault() }.forEach { or (it.bitSet) }
129
+ KotlinFeature .values().filter { it.enabledByDefault }.forEach { or (it.bitSet) }
129
130
}
130
131
131
132
fun withReflectionCacheSize (reflectionCacheSize : Int ) = apply {
@@ -140,13 +141,89 @@ class KotlinModule private constructor(
140
141
bitSet.andNot(feature.bitSet)
141
142
}
142
143
143
- fun set (feature : KotlinFeature , enabled : Boolean ) = when {
144
+ fun configure (feature : KotlinFeature , enabled : Boolean ) = when {
144
145
enabled -> enable(feature)
145
146
else -> disable(feature)
146
147
}
147
148
148
149
fun isEnabled (feature : KotlinFeature ): Boolean = bitSet.intersects(feature.bitSet)
149
150
151
+ @Deprecated(
152
+ message = " Deprecated, use withReflectionCacheSize(reflectionCacheSize) instead." ,
153
+ replaceWith = ReplaceWith (" isEnabled(reflectionCacheSize)" )
154
+ )
155
+ fun reflectionCacheSize (reflectionCacheSize : Int ) = apply {
156
+ this .reflectionCacheSize = reflectionCacheSize
157
+ }
158
+
159
+ @Deprecated(
160
+ message = " Deprecated, use isEnabled(NullToEmptyCollection) instead." ,
161
+ replaceWith = ReplaceWith (" isEnabled(NullToEmptyCollection)" )
162
+ )
163
+ fun getNullToEmptyCollection () = isEnabled(NullToEmptyCollection )
164
+
165
+ @Deprecated(
166
+ message = " Deprecated, use configure(NullToEmptyCollection, enabled) instead." ,
167
+ replaceWith = ReplaceWith (" configure(NullToEmptyCollection, enabled)" )
168
+ )
169
+ fun nullToEmptyCollection (nullToEmptyCollection : Boolean ) =
170
+ configure(NullToEmptyCollection , nullToEmptyCollection)
171
+
172
+ @Deprecated(
173
+ message = " Deprecated, use isEnabled(NullToEmptyMap) instead." ,
174
+ replaceWith = ReplaceWith (" isEnabled(NullToEmptyMap)" )
175
+ )
176
+
177
+ fun getNullToEmptyMap () = isEnabled(NullToEmptyMap )
178
+
179
+ @Deprecated(
180
+ message = " Deprecated, use configure(NullToEmptyMap, enabled) instead." ,
181
+ replaceWith = ReplaceWith (" configure(NullToEmptyMap, enabled)" )
182
+ )
183
+ fun nullToEmptyMap (nullToEmptyMap : Boolean ) = configure(NullToEmptyMap , nullToEmptyMap)
184
+
185
+ @Deprecated(
186
+ message = " Deprecated, use isEnabled(NullIsSameAsDefault) instead." ,
187
+ replaceWith = ReplaceWith (" isEnabled(NullIsSameAsDefault)" )
188
+ )
189
+ fun getNullIsSameAsDefault () = isEnabled(NullIsSameAsDefault )
190
+
191
+ @Deprecated(
192
+ message = " Deprecated, use configure(NullIsSameAsDefault, enabled) instead." ,
193
+ replaceWith = ReplaceWith (" configure(NullIsSameAsDefault, enabled)" )
194
+ )
195
+ fun nullIsSameAsDefault (nullIsSameAsDefault : Boolean ) = configure(NullIsSameAsDefault , nullIsSameAsDefault)
196
+
197
+ @Deprecated(
198
+ message = " Deprecated, use isEnabled(SingletonSupport) instead." ,
199
+ replaceWith = ReplaceWith (" isEnabled(SingletonSupport)" )
200
+ )
201
+ fun getSingletonSupport () = when {
202
+ isEnabled(KotlinFeature .SingletonSupport ) -> CANONICALIZE
203
+ else -> DISABLED
204
+ }
205
+
206
+ @Deprecated(
207
+ message = " Deprecated, use configure(SingletonSupport, enabled) instead." ,
208
+ replaceWith = ReplaceWith (" configure(SingletonSupport, enabled)" )
209
+ )
210
+ fun singletonSupport (singletonSupport : SingletonSupport ) = when (singletonSupport) {
211
+ CANONICALIZE -> enable(KotlinFeature .SingletonSupport )
212
+ else -> disable(KotlinFeature .SingletonSupport )
213
+ }
214
+
215
+ @Deprecated(
216
+ message = " Deprecated, use isEnabled(StrictNullChecks) instead." ,
217
+ replaceWith = ReplaceWith (" isEnabled(StrictNullChecks)" )
218
+ )
219
+ fun getStrictNullChecks () = isEnabled(StrictNullChecks )
220
+
221
+ @Deprecated(
222
+ message = " Deprecated, use configure(StrictNullChecks, enabled) instead." ,
223
+ replaceWith = ReplaceWith (" configure(StrictNullChecks, enabled)" )
224
+ )
225
+ fun strictNullChecks (strictNullChecks : Boolean ) = configure(StrictNullChecks , strictNullChecks)
226
+
150
227
fun build () = KotlinModule (this )
151
228
}
152
229
}
0 commit comments