or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

builtin-types.mdfactory-functions.mdindex.mdjson-node-operations.mdmodule-configuration.mdtype-safe-extensions.md
tile.json

tessl/maven-com-fasterxml-jackson-module--jackson-module-kotlin

Jackson module that adds comprehensive support for serialization and deserialization of Kotlin classes and data classes without requiring default constructors.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/com.fasterxml.jackson.module/jackson-module-kotlin@2.19.x

To install, run

npx @tessl/cli install tessl/maven-com-fasterxml-jackson-module--jackson-module-kotlin@2.19.0

index.mddocs/

Jackson Module Kotlin

Jackson 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.

Package Information

  • Package Name: jackson-module-kotlin
  • Package Type: maven
  • Language: Kotlin/Java
  • Installation:
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-kotlin</artifactId>
        <version>2.19.0</version>
    </dependency>

Core Imports

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue

Alternative imports:

import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.fasterxml.jackson.module.kotlin.jsonMapper
import com.fasterxml.jackson.module.kotlin.kotlinModule

Basic Usage

import 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)

Architecture

Jackson Module Kotlin integrates with the Jackson ecosystem through several key components:

  • KotlinModule: Main module class that registers Kotlin support with Jackson
  • KotlinFeature: Configuration enum for customizing module behavior
  • Extension Functions: Type-safe, reified extension functions for ObjectMapper operations
  • Introspectors: Kotlin-specific annotation and naming introspectors
  • Deserializers/Serializers: Built-in support for Kotlin-specific types
  • Reflection Cache: Optimized caching for Kotlin reflection operations

Capabilities

Module Configuration

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
}

Module Configuration

Factory Functions

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 = {}): KotlinModule

Factory Functions

Type-Safe Extensions

Reified 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>

Type-Safe Extensions

JSON Node Operations

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): Boolean

JSON Node Operations

Built-in Type Support

Comprehensive 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>

Built-in Type Support

Types

Core Types

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