Jackson module that adds comprehensive support for serialization and deserialization of Kotlin classes and data classes without requiring default constructors.
npx @tessl/cli install tessl/maven-com-fasterxml-jackson-module--jackson-module-kotlin@2.19.0Jackson Module Kotlin adds comprehensive support for serialization and deserialization of Kotlin classes and data classes without requiring default constructors. It enables automatic JSON property name inference from Kotlin constructor parameters using runtime type information, and supports single constructor classes, secondary constructors, and static factories.
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>2.19.0</version>
</dependency>import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValueAlternative imports:
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.fasterxml.jackson.module.kotlin.jsonMapper
import com.fasterxml.jackson.module.kotlin.kotlinModuleimport com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
data class User(val name: String, val age: Int)
// Create mapper with Kotlin support
val mapper = jacksonObjectMapper()
// Serialize to JSON
val user = User("Alice", 30)
val json = mapper.writeValueAsString(user)
// Deserialize from JSON with type inference
val deserializedUser = mapper.readValue<User>(json)
// or
val deserializedUser: User = mapper.readValue(json)Jackson Module Kotlin integrates with the Jackson ecosystem through several key components:
Core module setup and configuration with extensive customization options through feature flags and builder patterns.
class KotlinModule private constructor(
val reflectionCacheSize: Int = 512,
val nullToEmptyCollection: Boolean = false,
val nullToEmptyMap: Boolean = false,
val nullIsSameAsDefault: Boolean = false,
val singletonSupport: Boolean = false,
val strictNullChecks: Boolean = false,
val kotlinPropertyNameAsImplicitName: Boolean = false,
val useJavaDurationConversion: Boolean = false
) : SimpleModule
enum class KotlinFeature {
NullToEmptyCollection,
NullToEmptyMap,
NullIsSameAsDefault,
SingletonSupport,
StrictNullChecks,
NewStrictNullChecks,
KotlinPropertyNameAsImplicitName,
UseJavaDurationConversion
}Convenient factory functions for creating Jackson ObjectMappers and JsonMappers with Kotlin support enabled by default.
fun jacksonObjectMapper(): ObjectMapper
fun jacksonObjectMapper(initializer: KotlinModule.Builder.() -> Unit): ObjectMapper
fun jsonMapper(initializer: JsonMapper.Builder.() -> Unit = {}): JsonMapper
fun kotlinModule(initializer: KotlinModule.Builder.() -> Unit = {}): KotlinModuleReified extension functions that eliminate the need for explicit type references and provide compile-time type safety for all ObjectMapper operations.
inline fun <reified T> ObjectMapper.readValue(content: String): T
inline fun <reified T> ObjectMapper.readValue(src: File): T
inline fun <reified T> ObjectMapper.readValue(src: InputStream): T
inline fun <reified T> ObjectMapper.convertValue(from: Any?): T
inline fun <reified T> jacksonTypeRef(): TypeReference<T>Kotlin-style operator overloading for intuitive manipulation of Jackson's JSON tree model, enabling natural array and object operations.
operator fun ArrayNode.plus(element: String): Unit
operator fun ArrayNode.plusAssign(element: JsonNode): Unit
operator fun ObjectNode.minus(field: String): Unit
operator fun JsonNode.contains(field: String): BooleanComprehensive serialization and deserialization support for Kotlin-specific types including unsigned numbers, sequences, and value classes.
object UByteSerializer : StdSerializer<UByte>
object SequenceDeserializer : StdDeserializer<Sequence<*>>
object RegexDeserializer : StdDeserializer<Regex>
object ValueClassUnboxSerializer : StdSerializer<Any>class KotlinModule.Builder {
fun withReflectionCacheSize(size: Int): Builder
fun enable(feature: KotlinFeature): Builder
fun disable(feature: KotlinFeature): Builder
fun configure(feature: KotlinFeature, enabled: Boolean): Builder
fun isEnabled(feature: KotlinFeature): Boolean
fun build(): KotlinModule
}
class MissingKotlinParameterException(
val parameter: KParameter,
processor: JsonParser? = null,
msg: String
) : InvalidNullException