From 0a884aa989b059e8fba5f114d19236fa7b581c81 Mon Sep 17 00:00:00 2001 From: TheFruxz Date: Mon, 13 Feb 2023 16:57:26 +0100 Subject: [PATCH] Add missing remove function to JsonObjectBuilder --- formats/json/api/kotlinx-serialization-json.api | 1 + .../src/kotlinx/serialization/json/JsonElementBuilders.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/formats/json/api/kotlinx-serialization-json.api b/formats/json/api/kotlinx-serialization-json.api index 0d8c25e46d..224600111e 100644 --- a/formats/json/api/kotlinx-serialization-json.api +++ b/formats/json/api/kotlinx-serialization-json.api @@ -324,6 +324,7 @@ public final class kotlinx/serialization/json/JsonObjectBuilder { public fun ()V public final fun build ()Lkotlinx/serialization/json/JsonObject; public final fun put (Ljava/lang/String;Lkotlinx/serialization/json/JsonElement;)Lkotlinx/serialization/json/JsonElement; + public final fun remove (Ljava/lang/String;)Lkotlinx/serialization/json/JsonElement; } public final class kotlinx/serialization/json/JsonObjectSerializer : kotlinx/serialization/KSerializer { diff --git a/formats/json/commonMain/src/kotlinx/serialization/json/JsonElementBuilders.kt b/formats/json/commonMain/src/kotlinx/serialization/json/JsonElementBuilders.kt index b49a1aaaba..f3fef3949c 100644 --- a/formats/json/commonMain/src/kotlinx/serialization/json/JsonElementBuilders.kt +++ b/formats/json/commonMain/src/kotlinx/serialization/json/JsonElementBuilders.kt @@ -68,6 +68,14 @@ public class JsonObjectBuilder @PublishedApi internal constructor() { */ public fun put(key: String, element: JsonElement): JsonElement? = content.put(key, element) + /** + * Remove the JSON Element associated with the given [key]. + * + * Returns the previous value associated with [key], or `null` if the key was not present. + */ + @ExperimentalSerializationApi + public fun remove(key: String): JsonElement? = content.remove(key) + @PublishedApi internal fun build(): JsonObject = JsonObject(content) }