All Downloads are FREE. Search and download functionalities are using the official Maven repository.

implementations.StandardDecoder.kt Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
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
			)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy