implementations.StandardDecoder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluid-json-coding Show documentation
Show all versions of fluid-json-coding Show documentation
A JSON library written in pure Kotlin (coding extension)
package com.github.fluidsonic.fluid.json
internal class StandardDecoder(
override val context: Context,
private val codecProvider: JSONCodecProvider,
source: JSONReader
) : JSONDecoder, JSONReader by source {
override fun readValue() =
super.readValue()
override fun readValueOfType(valueType: JSONCodingType) =
codecProvider.decoderCodecForType(valueType)
?.run {
try {
isolateValueRead {
decode(valueType = valueType)
}
}
catch (e: JSONException) {
// TODO remove .java once KT-28418 is fixed
e.addSuppressed(JSONException.Parsing("… when decoding value of type $valueType using ${this::class.java.name}"))
throw e
}
}
?: throw JSONException.Parsing(
message = "No decoder codec registered for $valueType",
offset = offset,
path = path
)
}