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

factory-functions.mddocs/

Factory Functions

Convenient factory functions for creating Jackson ObjectMappers and JsonMappers with Kotlin support enabled by default.

Capabilities

Jackson ObjectMapper Factory

Create ObjectMapper instances with Kotlin module pre-registered for immediate use with Kotlin classes.

/**
 * Create an ObjectMapper with Kotlin module registered
 * @return ObjectMapper configured for Kotlin support
 */
fun jacksonObjectMapper(): ObjectMapper

/**
 * Create an ObjectMapper with custom Kotlin module configuration
 * @param initializer Lambda for configuring KotlinModule.Builder
 * @return ObjectMapper configured with custom Kotlin settings
 */
fun jacksonObjectMapper(initializer: KotlinModule.Builder.() -> Unit): ObjectMapper

Usage Examples:

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

// Simple mapper with default Kotlin support
val mapper = jacksonObjectMapper()

// Mapper with custom Kotlin configuration
val customMapper = jacksonObjectMapper {
    enable(KotlinFeature.NullToEmptyCollection)
    enable(KotlinFeature.SingletonSupport)
    withReflectionCacheSize(1024)
}

data class User(val name: String, val age: Int)
val user = User("Alice", 30)
val json = mapper.writeValueAsString(user)

JsonMapper Builder Factory

Create JsonMapper.Builder instances with Kotlin module pre-added for fluent configuration.

/**
 * Create a JsonMapper.Builder with Kotlin module added
 * @return JsonMapper.Builder configured for Kotlin support
 */
fun jacksonMapperBuilder(): JsonMapper.Builder

/**
 * Create a JsonMapper.Builder with custom Kotlin module configuration
 * @param initializer Lambda for configuring KotlinModule.Builder
 * @return JsonMapper.Builder configured with custom Kotlin settings
 */
fun jacksonMapperBuilder(initializer: KotlinModule.Builder.() -> Unit): JsonMapper.Builder

Usage Examples:

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

// Simple builder with default Kotlin support
val mapper = jacksonMapperBuilder().build()

// Builder with custom Kotlin configuration and other Jackson features
val customMapper = jacksonMapperBuilder {
    enable(KotlinFeature.StrictNullChecks)
    enable(KotlinFeature.NullIsSameAsDefault)
}
    .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    .build()

JsonMapper Factory

Create JsonMapper instances directly with optional configuration.

/**
 * Create a JsonMapper with optional configuration
 * @param initializer Lambda for configuring JsonMapper.Builder
 * @return JsonMapper instance
 */
fun jsonMapper(initializer: JsonMapper.Builder.() -> Unit = {}): JsonMapper

Usage Examples:

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

// Simple JsonMapper
val mapper = jsonMapper {
    addModule(kotlinModule())
}

// JsonMapper with custom Kotlin and Jackson configuration
val advancedMapper = jsonMapper {
    addModule(kotlinModule {
        enable(KotlinFeature.SingletonSupport)
        enable(KotlinFeature.UseJavaDurationConversion)
    })
    configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true)
}

KotlinModule Factory

Create KotlinModule instances with optional configuration for manual registration.

/**
 * Create a KotlinModule with optional configuration
 * @param initializer Lambda for configuring KotlinModule.Builder
 * @return KotlinModule instance
 */
fun kotlinModule(initializer: KotlinModule.Builder.() -> Unit = {}): KotlinModule

Usage Examples:

import com.fasterxml.jackson.module.kotlin.kotlinModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import com.fasterxml.jackson.databind.ObjectMapper

// Create module for manual registration
val module = kotlinModule {
    enable(KotlinFeature.NullToEmptyCollection)
    enable(KotlinFeature.NullToEmptyMap)
    withReflectionCacheSize(2048)
}

val mapper = ObjectMapper().registerModule(module)

Registration Extensions

Extension functions for adding Kotlin support to existing ObjectMapper instances.

/**
 * Register KotlinModule with an existing ObjectMapper
 * @return The same ObjectMapper instance for method chaining
 */
fun ObjectMapper.registerKotlinModule(): ObjectMapper

/**
 * Register KotlinModule with custom configuration to an existing ObjectMapper
 * @param initializer Lambda for configuring KotlinModule.Builder
 * @return The same ObjectMapper instance for method chaining
 */
fun ObjectMapper.registerKotlinModule(initializer: KotlinModule.Builder.() -> Unit): ObjectMapper

Usage Examples:

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature

// Add Kotlin support to existing mapper
val existingMapper = ObjectMapper()
existingMapper.registerKotlinModule()

// Add Kotlin support with custom configuration
val customMapper = ObjectMapper()
    .registerKotlinModule {
        enable(KotlinFeature.SingletonSupport)
        enable(KotlinFeature.NewStrictNullChecks)
    }
    .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)

Integration Patterns

Spring Boot Integration

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinFeature
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class JacksonConfig {
    
    @Bean
    fun objectMapper() = jacksonObjectMapper {
        enable(KotlinFeature.NullToEmptyCollection)
        enable(KotlinFeature.SingletonSupport)
    }
}

Ktor Integration

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*

fun Application.configureSerialization() {
    install(ContentNegotiation) {
        jackson {
            registerKotlinModule()
        }
    }
}

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