implementations.AbstractJSONDecoderCodec.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
import java.lang.reflect.*
import kotlin.reflect.*
abstract class AbstractJSONDecoderCodec(
private val additionalProviders: List> = emptyList(),
decodableType: JSONCodingType? = null
) : JSONDecoderCodec {
@Suppress("UNCHECKED_CAST")
final override val decodableType = decodableType
?: JSONCodingType.of((this::class.java.genericSuperclass as ParameterizedType).actualTypeArguments[0]) as JSONCodingType
override fun decoderCodecForType(decodableType: JSONCodingType): JSONDecoderCodec? {
var codec = super.decoderCodecForType(decodableType)
if (codec != null) {
return codec
}
for (provider in additionalProviders) {
codec = provider.decoderCodecForType(decodableType)
if (codec != null) {
return codec
}
}
return null
}
override fun encoderCodecForClass(encodableClass: KClass): JSONEncoderCodec? {
for (provider in additionalProviders) {
val codec = provider.encoderCodecForClass(encodableClass)
if (codec != null) {
return codec
}
}
return null
}
}