Skip to content

Commit

Permalink
Move json loaders into Ark companion
Browse files Browse the repository at this point in the history
  • Loading branch information
Lipen committed Jun 3, 2024
1 parent 01ce4ee commit 77696ff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,7 +33,23 @@ data class Ark(
val classes: List<Class>,
val importInfos: List<ImportInfo>,
val exportInfos: List<ExportInfo>,
)
) {
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(
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions jacodb-panda-dynamic/src/test/kotlin/ark/ArkFromJsonTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}

0 comments on commit 77696ff

Please sign in to comment.