Skip to content

Commit

Permalink
feat: added dtoFromJson method to TlcAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
janniclas committed Sep 2, 2024
1 parent a5f0bb1 commit 7a66d7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import de.fraunhofer.iem.kpiCalculator.model.adapter.tlc.TlcDefaultConfig
import de.fraunhofer.iem.kpiCalculator.model.adapter.tlc.TlcDto
import de.fraunhofer.iem.kpiCalculator.model.kpi.KpiId
import de.fraunhofer.iem.kpiCalculator.model.kpi.RawValueKpi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import java.io.InputStream

sealed class TechLagResult {
data class Success(val libyear: Long) : TechLagResult()
Expand All @@ -27,6 +31,16 @@ sealed class TechLagResult {

object TlcAdapter {

private val jsonParser = Json {
ignoreUnknownKeys = true
explicitNulls = false
}

@OptIn(ExperimentalSerializationApi::class)
fun dtoFromJson(jsonData: InputStream): TlcDto {
return jsonParser.decodeFromStream<TlcDto>(jsonData)
}

fun transformDataToKpi(
data: Collection<TlcDto>,
config: TlcConfig = TlcDefaultConfig.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ object TlcDefaultConfig {
)
)
}
}
}

0 comments on commit 7a66d7c

Please sign in to comment.