CtrlK
BlogDocsLog inGet started
Tessl Logo

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.

Pending
Overview
Eval results
Files

module-configuration.mddocs/

Module Configuration

Core module setup and configuration with extensive customization options through feature flags and builder patterns.

Capabilities

KotlinModule

Main Jackson module class that integrates Kotlin support with Jackson's core functionality.

/**
 * Main Jackson module class for Kotlin support
 * @property reflectionCacheSize Size of the caches used for mapping objects (default: 512)
 * @property nullToEmptyCollection Whether to deserialize null collections as empty
 * @property nullToEmptyMap Whether to deserialize null maps as empty
 * @property nullIsSameAsDefault Whether null values use Kotlin default values
 * @property singletonSupport Whether to support Kotlin object singletons
 * @property strictNullChecks Whether to check collection nullability
 * @property kotlinPropertyNameAsImplicitName Whether to use Kotlin property names
 * @property useJavaDurationConversion Whether to convert kotlin.time.Duration
 */
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

Usage Examples:

import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.databind.ObjectMapper

// Create module with default settings
val module = KotlinModule.Builder().build()
val mapper = ObjectMapper().registerModule(module)

// Create module with custom configuration
val customModule = KotlinModule.Builder()
    .enable(KotlinFeature.NullToEmptyCollection)
    .enable(KotlinFeature.SingletonSupport)
    .withReflectionCacheSize(1024)
    .build()

KotlinModule.Builder

Builder class for configuring KotlinModule instances with method chaining.

/**
 * Builder for configuring KotlinModule instances
 */
class Builder {
    /** Set the size of reflection caches */
    fun withReflectionCacheSize(size: Int): Builder
    /** Enable a specific Kotlin feature */
    fun enable(feature: KotlinFeature): Builder
    /** Disable a specific Kotlin feature */
    fun disable(feature: KotlinFeature): Builder
    /** Configure a feature as enabled or disabled */
    fun configure(feature: KotlinFeature, enabled: Boolean): Builder
    /** Check if a feature is currently enabled */
    fun isEnabled(feature: KotlinFeature): Boolean
    /** Build the final KotlinModule instance */
    fun build(): KotlinModule
}

KotlinFeature

Enum defining all configurable features available in the Kotlin module.

/**
 * Configurable features for the Kotlin module
 */
enum class KotlinFeature(internal val enabledByDefault: Boolean) {
    /** Convert null collections to empty collections */
    NullToEmptyCollection(enabledByDefault = false),
    /** Convert null maps to empty maps */
    NullToEmptyMap(enabledByDefault = false),
    /** Use Kotlin default values for null parameters */
    NullIsSameAsDefault(enabledByDefault = false),
    /** Handle Kotlin object singletons properly */
    SingletonSupport(enabledByDefault = false),
    /** Check collection nullability (deprecated, use NewStrictNullChecks) */
    StrictNullChecks(enabledByDefault = false),
    /** Improved null checking with better performance */
    NewStrictNullChecks(enabledByDefault = false),
    /** Use Kotlin property names for serialization */
    KotlinPropertyNameAsImplicitName(enabledByDefault = false),
    /** Convert kotlin.time.Duration via java.time.Duration */
    UseJavaDurationConversion(enabledByDefault = false)
}

Feature Configuration Examples:

import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature

// Enable null-to-empty collection conversion
val module = KotlinModule.Builder()
    .enable(KotlinFeature.NullToEmptyCollection)
    .enable(KotlinFeature.NullToEmptyMap)
    .build()

// Configure strict null checking
val strictModule = KotlinModule.Builder()
    .enable(KotlinFeature.NewStrictNullChecks)
    .build()

// Support for Kotlin singletons
val singletonModule = KotlinModule.Builder()
    .enable(KotlinFeature.SingletonSupport)
    .build()

Class Extension

Utility function for detecting Kotlin classes.

/**
 * Extension function to check if a class is a Kotlin class
 * @return true if the class is annotated with Kotlin's @Metadata annotation
 */
fun Class<*>.isKotlinClass(): Boolean

Usage Examples:

import com.fasterxml.jackson.module.kotlin.isKotlinClass

data class KotlinClass(val name: String)
class JavaClass { String name; }

val isKotlin = KotlinClass::class.java.isKotlinClass() // true
val isJava = JavaClass::class.java.isKotlinClass()     // false

Exception Handling

MissingKotlinParameterException

Specialized exception for missing Kotlin constructor parameters (deprecated in favor of more general Jackson exceptions).

/**
 * Specialized exception for missing Kotlin constructor parameters
 * @param parameter The missing Kotlin parameter (deprecated - not serializable)
 * @param processor JsonParser instance where error occurred
 * @param msg Error message
 * @deprecated Use MismatchedInputException instead
 */
@Deprecated("Use MismatchedInputException instead")
class MissingKotlinParameterException(
    @Deprecated("KParameter is not serializable")
    @Transient
    val parameter: KParameter,
    processor: JsonParser? = null,
    msg: String
) : InvalidNullException

Install with Tessl CLI

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

docs

builtin-types.md

factory-functions.md

index.md

json-node-operations.md

module-configuration.md

type-safe-extensions.md

tile.json