uidsonic.fluid-json-coding.0.9.10.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 {
val basic = of(DefaultJSONCodecs.basic + DefaultJSONCodecs.nonRecursive)
val extended = of(DefaultJSONCodecs.extended + DefaultJSONCodecs.basic + DefaultJSONCodecs.nonRecursive)
fun of(
vararg providers: JSONCodecProvider,
base: JSONCodecProvider? = extended
) =
of(providers.asIterable(), base = base)
fun of(
providers: Iterable>,
base: JSONCodecProvider? = extended
): JSONCodecProvider =
StandardCodecProvider(providers = base?.let { providers + it } ?: providers)
}
}
inline fun JSONCodecProvider.decoderCodecForType() =
decoderCodecForType(jsonCodingType())
inline fun JSONCodecProvider.encoderCodecForClass() =
encoderCodecForClass(Value::class)