diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt index 3e025f2f0..a9da15d46 100644 --- a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt +++ b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/Ark.kt @@ -16,7 +16,12 @@ package org.jacodb.panda.dynamic.ark.dto +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.decodeFromStream +import java.io.InputStream @Serializable data class Ark( @@ -28,7 +33,23 @@ data class Ark( val classes: List, val importInfos: List, val exportInfos: List, -) +) { + companion object{ + private val json = Json { + classDiscriminator = "_" + prettyPrint = true + } + + fun loadFromJson(jsonString: String): Ark { + return json.decodeFromString(jsonString) + } + + @OptIn(ExperimentalSerializationApi::class) + fun loadFromJson(stream: InputStream): Ark { + return json.decodeFromStream(stream) + } + } +} @Serializable data class Namespace( diff --git a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt b/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt deleted file mode 100644 index ce27b88a3..000000000 --- a/jacodb-panda-dynamic/src/main/kotlin/org/jacodb/panda/dynamic/ark/dto/io.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022 UnitTestBot contributors (utbot.org) - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jacodb.panda.dynamic.ark.dto - -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.decodeFromString -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream -import java.io.InputStream - -private val json = Json { - classDiscriminator = "_" - prettyPrint = true -} - -fun loadArkFromJson(jsonString: String): Ark { - return json.decodeFromString(jsonString) -} - -@OptIn(ExperimentalSerializationApi::class) -fun loadArkFromJson(stream: InputStream): Ark { - return json.decodeFromStream(stream) -} diff --git a/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt b/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt index c03aa118e..1ba3d366b 100644 --- a/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt +++ b/jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt @@ -16,7 +16,7 @@ package ark -import org.jacodb.panda.dynamic.ark.dto.loadArkFromJson +import org.jacodb.panda.dynamic.ark.dto.Ark import org.junit.jupiter.api.Test class ArkFromJsonTest { @@ -25,7 +25,7 @@ class ArkFromJsonTest { val path = "basic.ts.json" val stream = object {}::class.java.getResourceAsStream("/$path") ?: error("Resource not found: $path") - val ark = loadArkFromJson(stream) + val ark = Ark.loadFromJson(stream) println(ark) } }