uidsonic.fluid-json-coding.0.9.16.source-code.JSONCodecProvider.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 kotlin.reflect.KClass
interface JSONCodecProvider {
fun decoderCodecForType(decodableType: JSONCodingType): JSONDecoderCodec?
fun encoderCodecForClass(encodableClass: KClass): JSONEncoderCodec?
companion object {
@Deprecated(message = "replaced by JSONCodecProvider(…), but be careful because that one no longer adds base providers automatically")
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
fun of(
vararg providers: JSONCodecProvider,
base: JSONCodecProvider? = JSONCodecProvider.extended
) =
of(providers.asIterable(), base = base)
@Deprecated(message = "replaced by JSONCodecProvider(…), but be careful because that one no longer adds base providers automatically")
@Suppress("DeprecatedCallableAddReplaceWith")
fun of(
providers: Iterable>,
base: JSONCodecProvider? = JSONCodecProvider.extended
): JSONCodecProvider =
FixedCodecProvider(providers = base?.let { providers + it } ?: providers)
}
}
private val basicProvider = JSONCodecProvider(DefaultJSONCodecs.basic + DefaultJSONCodecs.nonRecursive)
private val extendedProvider = JSONCodecProvider(DefaultJSONCodecs.extended + DefaultJSONCodecs.basic + DefaultJSONCodecs.nonRecursive)
val JSONCodecProvider.Companion.basic
get() = basicProvider
inline fun JSONCodecProvider.decoderCodecForType() =
decoderCodecForType(jsonCodingType())
inline fun JSONCodecProvider.encoderCodecForClass() =
encoderCodecForClass(ActualValue::class)
val JSONCodecProvider.Companion.extended
get() = extendedProvider
fun > JSONCodecProvider.Companion.generated(interfaceClass: KClass): CodecProvider =
error("Cannot find annotation-based codec provider. Either $interfaceClass hasn't been annotated with @JSON.CodecProvider or kapt hasn't been run.")