Skip to content

Commit c487e78

Browse files
authored
JSON: Fix mutable classDiscriminatorMode in config, and mark experimental in builder (#2680)
Since this is a new feature, it should have been added as experimental to the builder, but it wasn't done properly. Deprecate mutable `classDiscriminatorMode` in `JsonConfiguration` — vars are not needed there.
1 parent 385c97d commit c487e78

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

formats/json/commonMain/src/kotlinx/serialization/json/Json.kt

+1
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ public class JsonBuilder internal constructor(json: Json) {
502502
* Other modes are generally intended to produce JSON for consumption by third-party libraries,
503503
* therefore, this setting does not affect the deserialization process.
504504
*/
505+
@ExperimentalSerializationApi
505506
public var classDiscriminatorMode: ClassDiscriminatorMode = json.configuration.classDiscriminatorMode
506507

507508
/**

formats/json/commonMain/src/kotlinx/serialization/json/JsonConfiguration.kt

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public class JsonConfiguration @OptIn(ExperimentalSerializationApi::class) inter
3939
@ExperimentalSerializationApi
4040
public val allowComments: Boolean = false,
4141
@ExperimentalSerializationApi
42+
@set:Deprecated(
43+
"JsonConfiguration is not meant to be mutable, and will be made read-only in a future release. " +
44+
"The `Json(from = ...) {}` copy builder should be used instead.",
45+
level = DeprecationLevel.ERROR
46+
)
4247
public var classDiscriminatorMode: ClassDiscriminatorMode = ClassDiscriminatorMode.POLYMORPHIC,
4348
) {
4449

0 commit comments

Comments
 (0)