or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

module-configuration.mddocs/

0

# Module Configuration

1

2

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

3

4

## Capabilities

5

6

### KotlinModule

7

8

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

9

10

```kotlin { .api }

11

/**

12

* Main Jackson module class for Kotlin support

13

* @property reflectionCacheSize Size of the caches used for mapping objects (default: 512)

14

* @property nullToEmptyCollection Whether to deserialize null collections as empty

15

* @property nullToEmptyMap Whether to deserialize null maps as empty

16

* @property nullIsSameAsDefault Whether null values use Kotlin default values

17

* @property singletonSupport Whether to support Kotlin object singletons

18

* @property strictNullChecks Whether to check collection nullability

19

* @property kotlinPropertyNameAsImplicitName Whether to use Kotlin property names

20

* @property useJavaDurationConversion Whether to convert kotlin.time.Duration

21

*/

22

class KotlinModule private constructor(

23

val reflectionCacheSize: Int = 512,

24

val nullToEmptyCollection: Boolean = false,

25

val nullToEmptyMap: Boolean = false,

26

val nullIsSameAsDefault: Boolean = false,

27

val singletonSupport: Boolean = false,

28

val strictNullChecks: Boolean = false,

29

val kotlinPropertyNameAsImplicitName: Boolean = false,

30

val useJavaDurationConversion: Boolean = false

31

) : SimpleModule

32

```

33

34

**Usage Examples:**

35

36

```kotlin

37

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

38

import com.fasterxml.jackson.databind.ObjectMapper

39

40

// Create module with default settings

41

val module = KotlinModule.Builder().build()

42

val mapper = ObjectMapper().registerModule(module)

43

44

// Create module with custom configuration

45

val customModule = KotlinModule.Builder()

46

.enable(KotlinFeature.NullToEmptyCollection)

47

.enable(KotlinFeature.SingletonSupport)

48

.withReflectionCacheSize(1024)

49

.build()

50

```

51

52

### KotlinModule.Builder

53

54

Builder class for configuring KotlinModule instances with method chaining.

55

56

```kotlin { .api }

57

/**

58

* Builder for configuring KotlinModule instances

59

*/

60

class Builder {

61

/** Set the size of reflection caches */

62

fun withReflectionCacheSize(size: Int): Builder

63

/** Enable a specific Kotlin feature */

64

fun enable(feature: KotlinFeature): Builder

65

/** Disable a specific Kotlin feature */

66

fun disable(feature: KotlinFeature): Builder

67

/** Configure a feature as enabled or disabled */

68

fun configure(feature: KotlinFeature, enabled: Boolean): Builder

69

/** Check if a feature is currently enabled */

70

fun isEnabled(feature: KotlinFeature): Boolean

71

/** Build the final KotlinModule instance */

72

fun build(): KotlinModule

73

}

74

```

75

76

### KotlinFeature

77

78

Enum defining all configurable features available in the Kotlin module.

79

80

```kotlin { .api }

81

/**

82

* Configurable features for the Kotlin module

83

*/

84

enum class KotlinFeature(internal val enabledByDefault: Boolean) {

85

/** Convert null collections to empty collections */

86

NullToEmptyCollection(enabledByDefault = false),

87

/** Convert null maps to empty maps */

88

NullToEmptyMap(enabledByDefault = false),

89

/** Use Kotlin default values for null parameters */

90

NullIsSameAsDefault(enabledByDefault = false),

91

/** Handle Kotlin object singletons properly */

92

SingletonSupport(enabledByDefault = false),

93

/** Check collection nullability (deprecated, use NewStrictNullChecks) */

94

StrictNullChecks(enabledByDefault = false),

95

/** Improved null checking with better performance */

96

NewStrictNullChecks(enabledByDefault = false),

97

/** Use Kotlin property names for serialization */

98

KotlinPropertyNameAsImplicitName(enabledByDefault = false),

99

/** Convert kotlin.time.Duration via java.time.Duration */

100

UseJavaDurationConversion(enabledByDefault = false)

101

}

102

```

103

104

**Feature Configuration Examples:**

105

106

```kotlin

107

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

108

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

109

110

// Enable null-to-empty collection conversion

111

val module = KotlinModule.Builder()

112

.enable(KotlinFeature.NullToEmptyCollection)

113

.enable(KotlinFeature.NullToEmptyMap)

114

.build()

115

116

// Configure strict null checking

117

val strictModule = KotlinModule.Builder()

118

.enable(KotlinFeature.NewStrictNullChecks)

119

.build()

120

121

// Support for Kotlin singletons

122

val singletonModule = KotlinModule.Builder()

123

.enable(KotlinFeature.SingletonSupport)

124

.build()

125

```

126

127

### Class Extension

128

129

Utility function for detecting Kotlin classes.

130

131

```kotlin { .api }

132

/**

133

* Extension function to check if a class is a Kotlin class

134

* @return true if the class is annotated with Kotlin's @Metadata annotation

135

*/

136

fun Class<*>.isKotlinClass(): Boolean

137

```

138

139

**Usage Examples:**

140

141

```kotlin

142

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

143

144

data class KotlinClass(val name: String)

145

class JavaClass { String name; }

146

147

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

148

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

149

```

150

151

## Exception Handling

152

153

### MissingKotlinParameterException

154

155

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

156

157

```kotlin { .api }

158

/**

159

* Specialized exception for missing Kotlin constructor parameters

160

* @param parameter The missing Kotlin parameter (deprecated - not serializable)

161

* @param processor JsonParser instance where error occurred

162

* @param msg Error message

163

* @deprecated Use MismatchedInputException instead

164

*/

165

@Deprecated("Use MismatchedInputException instead")

166

class MissingKotlinParameterException(

167

@Deprecated("KParameter is not serializable")

168

@Transient

169

val parameter: KParameter,

170

processor: JsonParser? = null,

171

msg: String

172

) : InvalidNullException

173

```