or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdjackson-modules.mdobject-mapper-factory.mdproperty-naming.mdsubtype-discovery.md

jackson-modules.mddocs/

0

# Jackson Modules

1

2

Dropwizard Jackson provides several custom Jackson modules that extend serialization capabilities for specific types and use cases commonly found in Dropwizard applications.

3

4

## CaffeineModule

5

6

Jackson module that provides serialization and deserialization support for Caffeine cache specifications.

7

8

```java { .api }

9

public class CaffeineModule extends Module {

10

public String getModuleName() // Returns "CaffeineModule"

11

public Version version()

12

public void setupModule(SetupContext context)

13

}

14

```

15

16

**Supported Types**:

17

- `com.github.benmanes.caffeine.cache.CaffeineSpec`

18

19

**Serialization Behavior**:

20

- Serializes CaffeineSpec objects to their parseable string representation

21

- Deserializes string values back to CaffeineSpec objects

22

- Handles "off" and "disabled" as special values for disabled caching

23

24

**Usage Example**:

25

```java

26

ObjectMapper mapper = Jackson.newObjectMapper(); // CaffeineModule automatically included

27

28

CaffeineSpec spec = CaffeineSpec.parse("maximumSize=1000,expireAfterWrite=30s");

29

String json = mapper.writeValueAsString(spec);

30

// Result: "maximumSize=1000,expireAfterWrite=30s"

31

32

CaffeineSpec deserialized = mapper.readValue(json, CaffeineSpec.class);

33

```

34

35

## FuzzyEnumModule

36

37

Jackson module that provides permissive enum deserialization, handling common formatting variations.

38

39

```java { .api }

40

public class FuzzyEnumModule extends Module {

41

public String getModuleName() // Returns "permissive-enums"

42

public Version version()

43

public void setupModule(SetupContext context)

44

}

45

```

46

47

**Deserialization Features**:

48

- **Case Insensitive**: Matches enum values regardless of case

49

- **Whitespace Handling**: Strips leading and trailing whitespace

50

- **Character Normalization**: Converts dashes and periods to underscores

51

- **Flexible Matching**: Uses `Enums.fromStringFuzzy()` utility for permissive matching

52

- **Error Handling**: Provides clear error messages listing accepted values when deserialization fails

53

54

**Behavior Conditions**:

55

- Only applies when no `@JsonCreator` annotation is present

56

- Disabled when `READ_ENUMS_USING_TO_STRING` feature is enabled

57

- Disabled when `READ_UNKNOWN_ENUM_VALUES_AS_NULL` feature is enabled

58

- Disabled when `READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE` feature is enabled

59

- Disabled when enum fields have Jackson annotations from `com.fasterxml.jackson.annotation` package

60

61

**Usage Example**:

62

```java

63

public enum Status {

64

ACTIVE, INACTIVE, PENDING

65

}

66

67

ObjectMapper mapper = Jackson.newObjectMapper(); // FuzzyEnumModule automatically included

68

69

// All of these will deserialize to Status.ACTIVE:

70

Status active1 = mapper.readValue("\"active\"", Status.class);

71

Status active2 = mapper.readValue("\"ACTIVE\"", Status.class);

72

Status active3 = mapper.readValue("\" active \"", Status.class);

73

Status active4 = mapper.readValue("\"act-ive\"", Status.class);

74

```

75

76

## GuavaExtrasModule

77

78

Jackson module that provides serialization and deserialization support for Guava cache builder specifications.

79

80

```java { .api }

81

public class GuavaExtrasModule extends Module {

82

public String getModuleName() // Returns "guava-extras"

83

public Version version()

84

public void setupModule(SetupContext context)

85

}

86

```

87

88

**Supported Types**:

89

- `com.google.common.cache.CacheBuilderSpec`

90

91

**Serialization Behavior**:

92

- Serializes CacheBuilderSpec objects to their parseable string representation

93

- Deserializes string values back to CacheBuilderSpec objects

94

- Handles "off" and "disabled" as special values for disabled caching

95

96

**Usage Example**:

97

```java

98

ObjectMapper mapper = Jackson.newObjectMapper(); // GuavaExtrasModule automatically included

99

100

CacheBuilderSpec spec = CacheBuilderSpec.parse("maximumSize=500,expireAfterAccess=10m");

101

String json = mapper.writeValueAsString(spec);

102

// Result: "maximumSize=500,expireAfterAccess=10m"

103

104

CacheBuilderSpec deserialized = mapper.readValue(json, CacheBuilderSpec.class);

105

106

// Special handling for disabled caches

107

CacheBuilderSpec disabled = mapper.readValue("\"disabled\"", CacheBuilderSpec.class);

108

// Results in CacheBuilderSpec.disableCaching()

109

```

110

111

## Module Registration

112

113

All modules are automatically registered when using Jackson factory methods:

114

115

```java

116

ObjectMapper mapper = Jackson.newObjectMapper();

117

// All three modules (CaffeineModule, FuzzyEnumModule, GuavaExtrasModule) are pre-registered

118

119

ObjectMapper minimal = Jackson.newMinimalObjectMapper();

120

// Only GuavaModule is registered (not the custom Dropwizard modules)

121

```

122

123

## Integration with Standard Modules

124

125

The custom modules work alongside standard Jackson modules that are also automatically registered:

126

127

- **GuavaModule**: Basic Guava collections support

128

- **ParameterNamesModule**: Constructor parameter name preservation

129

- **Jdk8Module**: Java 8 Optional and Stream support

130

- **JavaTimeModule**: JSR-310 time types (LocalDate, Instant, etc.)

131

- **Performance Modules**: Afterburner or Blackbird for optimization