Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/docker-kotlin.api
Original file line number Diff line number Diff line change
Expand Up @@ -4020,8 +4020,9 @@ public final class me/devnatan/dockerkt/resource/volume/VolumeResourceKt {
public static final fun remove (Lme/devnatan/dockerkt/resource/volume/VolumeResource;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class me/devnatan/dockerkt/util/JsonKt {
public final synthetic class me/devnatan/dockerkt/util/JsonKt {
public static final fun fromJsonEncodedString (Ljava/lang/String;)Ljava/util/Map;
public static final fun getDockerKotlinJson ()Lkotlinx/serialization/json/Json;
public static final fun toJsonEncodedString (Ljava/lang/Object;)Ljava/lang/String;
}

2 changes: 2 additions & 0 deletions api/docker-kotlin.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,8 @@ final val me.devnatan.dockerkt.models.image/created // me.devnatan.dockerkt.mode
final fun (me.devnatan.dockerkt.models.image/Image).<get-created>(): kotlin.time/Instant // me.devnatan.dockerkt.models.image/created.<get-created>|<get-created>@me.devnatan.dockerkt.models.image.Image(){}[0]
final val me.devnatan.dockerkt.models.system/time // me.devnatan.dockerkt.models.system/time|@me.devnatan.dockerkt.models.system.Event{}time[0]
final fun (me.devnatan.dockerkt.models.system/Event).<get-time>(): kotlin.time/Instant // me.devnatan.dockerkt.models.system/time.<get-time>|<get-time>@me.devnatan.dockerkt.models.system.Event(){}[0]
final val me.devnatan.dockerkt.util/DockerKotlinJson // me.devnatan.dockerkt.util/DockerKotlinJson|{}DockerKotlinJson[0]
final fun <get-DockerKotlinJson>(): kotlinx.serialization.json/Json // me.devnatan.dockerkt.util/DockerKotlinJson.<get-DockerKotlinJson>|<get-DockerKotlinJson>(){}[0]

final var me.devnatan.dockerkt.models.container/stopTimeout // me.devnatan.dockerkt.models.container/stopTimeout|@me.devnatan.dockerkt.models.container.ContainerCreateOptions{}stopTimeout[0]
final fun (me.devnatan.dockerkt.models.container/ContainerCreateOptions).<get-stopTimeout>(): kotlin.time/Duration? // me.devnatan.dockerkt.models.container/stopTimeout.<get-stopTimeout>|<get-stopTimeout>@me.devnatan.dockerkt.models.container.ContainerCreateOptions(){}[0]
Expand Down
12 changes: 7 additions & 5 deletions src/commonMain/kotlin/me/devnatan/dockerkt/util/Json.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
@file:JvmSynthetic

package me.devnatan.dockerkt.util

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlin.jvm.JvmSynthetic

private val json: Json =
public val DockerKotlinJson: Json =
Json {
ignoreUnknownKeys = true
isLenient = true
allowStructuredMapKeys = true
coerceInputValues = true
}

public fun toJsonEncodedString(value: Any): String = json.encodeToString(value)
public fun toJsonEncodedString(value: Any): String = DockerKotlinJson.encodeToString(value)

public fun fromJsonEncodedString(value: String): Map<String, String?> = json.decodeFromString(value)
public fun fromJsonEncodedString(value: String): Map<String, String?> = DockerKotlinJson.decodeFromString(value)
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive

internal open class ListAsMapToEmptyObjectsSerializer<T : Any>(
private val tSerializer: KSerializer<T>,
) : JsonTransformingSerializer<List<T>>(ListSerializer(tSerializer)) {
serializer: KSerializer<T>,
) : JsonTransformingSerializer<List<T>>(ListSerializer(serializer)) {
override fun transformDeserialize(element: JsonElement): JsonElement =
JsonArray(element.jsonObject.entries.map { JsonPrimitive(it.key) })

Expand Down
24 changes: 24 additions & 0 deletions src/commonTest/kotlin/me/devnatan/dockerkt/util/JsonTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.devnatan.dockerkt.util

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlin.test.Test
import kotlin.test.assertEquals

class JsonTest {
@Test
fun `deserialization of nullable api field with default value`() {
@Serializable
data class Entity(
@SerialName("Cmd") val command: List<String> = emptyList(),
)

val json = """{"Cmd": null}"""
val entity = DockerKotlinJson.decodeFromString<Entity>(json)

assertEquals(
expected = Entity(command = emptyList()),
actual = entity,
)
}
}
3 changes: 2 additions & 1 deletion src/jvmMain/kotlin/me/devnatan/dockerkt/DockerClient.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import me.devnatan.dockerkt.resource.network.NetworkResource
import me.devnatan.dockerkt.resource.secret.SecretResource
import me.devnatan.dockerkt.resource.system.SystemResource
import me.devnatan.dockerkt.resource.volume.VolumeResource
import me.devnatan.dockerkt.util.DockerKotlinJson
import kotlin.coroutines.CoroutineContext

public actual class DockerClient public actual constructor(
Expand All @@ -22,7 +23,7 @@ public actual class DockerClient public actual constructor(

actual override val coroutineContext: CoroutineContext = SupervisorJob()

public actual val json: Json = Json { ignoreUnknownKeys = true }
public actual val json: Json get() = DockerKotlinJson
public actual val httpClient: HttpClient = createHttpClient(this)

@get:JvmName("images")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import me.devnatan.dockerkt.resource.network.NetworkResource
import me.devnatan.dockerkt.resource.secret.SecretResource
import me.devnatan.dockerkt.resource.system.SystemResource
import me.devnatan.dockerkt.resource.volume.VolumeResource
import me.devnatan.dockerkt.util.DockerKotlinJson
import kotlin.coroutines.CoroutineContext

public actual class DockerClient public actual constructor(
Expand All @@ -21,7 +22,7 @@ public actual class DockerClient public actual constructor(
Closeable {
actual override val coroutineContext: CoroutineContext = SupervisorJob()

public actual val json: Json = Json { ignoreUnknownKeys = true }
public actual val json: Json get() = DockerKotlinJson
public actual val httpClient: HttpClient = createHttpClient(this)

public actual val images: ImageResource = ImageResource(httpClient, json)
Expand Down
Loading