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

uidsonic.fluid-json-coding.0.9.22.source-code.JSONCodecProvider.kt Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
package com.github.fluidsonic.fluid.json

import kotlin.reflect.*


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.")




© 2015 - 2024 Weber Informatics LLC | Privacy Policy