Skip to content

Commit

Permalink
remove JsonArrayBuilder addAll varargs util
Browse files Browse the repository at this point in the history
  • Loading branch information
aSemy committed May 1, 2023
1 parent 2b01d9c commit f6f64f2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,23 @@ class JsonBuildersTest {
@Test
fun testBuildJsonArrayAddAll() {
assertEquals(
"""[1,2,3,4,5,null,1,2,3,4,5,null]""",
"""[1,2,3,4,5,null]""",
buildJsonArray {
assertTrue { addAll(1) }
assertTrue { addAll(2, 3, 4, 5, null) }
assertTrue { addAll(listOf(1, 2, 3, 4, 5, null)) }
}.toString()
)

assertEquals(
"""["a","b","c",null,"a","b","c",null]""",
"""["a","b","c",null]""",
buildJsonArray {
assertTrue { addAll("a") }
assertTrue { addAll("b", "c", null) }
assertTrue { addAll(listOf("a", "b", "c", null)) }
}.toString()
)

assertEquals(
"""[true,true,true,null,false,false,false,null]""",
"""[true,false,null]""",
buildJsonArray {
assertTrue { addAll(true) }
assertTrue { addAll(true, true, null) }
assertTrue { addAll(listOf(false, false, false, null)) }
assertTrue { addAll(listOf(true, false, null)) }
}.toString()
)

Expand All @@ -90,7 +84,7 @@ class JsonBuildersTest {
JsonPrimitive(2),
JsonPrimitive("b"),
JsonPrimitive(true),
JsonNull
JsonNull,
)
)
}
Expand Down Expand Up @@ -163,11 +157,6 @@ class JsonBuildersTest {
assertEquals(
"""[]""",
buildJsonArray {
// varargs
assertFalse { addAll(*arrayOf<String>()) }
assertFalse { addAll(*arrayOf<Boolean>()) }
assertFalse { addAll(*arrayOf<Number>()) }

// add collections
assertFalse { addAll(listOf<Number>()) }
assertFalse { addAll(listOf<String>()) }
Expand Down
3 changes: 0 additions & 3 deletions formats/json/api/kotlinx-serialization-json.api
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ public final class kotlinx/serialization/json/JsonElementBuildersKt {
public static final fun add (Lkotlinx/serialization/json/JsonArrayBuilder;Ljava/lang/Number;)Z
public static final fun add (Lkotlinx/serialization/json/JsonArrayBuilder;Ljava/lang/String;)Z
public static final fun add (Lkotlinx/serialization/json/JsonArrayBuilder;Ljava/lang/Void;)Z
public static final fun addAll (Lkotlinx/serialization/json/JsonArrayBuilder;[Ljava/lang/Boolean;)Z
public static final fun addAll (Lkotlinx/serialization/json/JsonArrayBuilder;[Ljava/lang/Number;)Z
public static final fun addAll (Lkotlinx/serialization/json/JsonArrayBuilder;[Ljava/lang/String;)Z
public static final fun addAll (Lkotlinx/serialization/json/JsonArrayBuilder;[Lkotlinx/serialization/json/JsonElement;)Z
public static final fun addAllBooleans (Lkotlinx/serialization/json/JsonArrayBuilder;Ljava/util/Collection;)Z
public static final fun addAllNumbers (Lkotlinx/serialization/json/JsonArrayBuilder;Ljava/util/Collection;)Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,5 @@ public fun JsonArrayBuilder.addAll(values: Collection<Boolean?>): Boolean =
public fun JsonArrayBuilder.addAll(values: Collection<Number?>): Boolean =
addAll(values.map(::JsonPrimitive))

/** Adds the given string [values] to a resulting JSON array. */
@ExperimentalSerializationApi
public fun JsonArrayBuilder.addAll(vararg values: String?): Boolean =
addAll(values.toList())

/** Adds the given boolean [values] to a resulting JSON array. */
@ExperimentalSerializationApi
public fun JsonArrayBuilder.addAll(vararg values: Boolean?): Boolean =
addAll(values.toList())

/** Adds the given numeric [values] to a resulting JSON array. */
@ExperimentalSerializationApi
public fun JsonArrayBuilder.addAll(vararg values: Number?): Boolean =
addAll(values.toList())

@DslMarker
internal annotation class JsonDslMarker

0 comments on commit f6f64f2

Please sign in to comment.