0
# Dropwizard Jackson
1
2
Dropwizard Jackson provides comprehensive Jackson JSON processing support for Dropwizard applications. It offers pre-configured ObjectMapper instances with sensible defaults and essential modules for handling Guava collections, Java 8 Optional and time types, parameter name preservation, enum fuzzy matching, and high-performance serialization.
3
4
## Package Information
5
6
- **Package Name**: io.dropwizard:dropwizard-jackson
7
- **Package Type**: Maven
8
- **Language**: Java
9
- **Installation**: Add to Maven dependencies:
10
11
```xml
12
<dependency>
13
<groupId>io.dropwizard</groupId>
14
<artifactId>dropwizard-jackson</artifactId>
15
<version>4.0.14</version>
16
</dependency>
17
```
18
19
## Core Imports
20
21
```java
22
import io.dropwizard.jackson.Jackson;
23
import io.dropwizard.jackson.JsonSnakeCase;
24
import io.dropwizard.jackson.Discoverable;
25
import com.fasterxml.jackson.databind.ObjectMapper;
26
```
27
28
## Basic Usage
29
30
```java
31
import io.dropwizard.jackson.Jackson;
32
import com.fasterxml.jackson.databind.ObjectMapper;
33
34
// Create a fully configured ObjectMapper
35
ObjectMapper mapper = Jackson.newObjectMapper();
36
37
// Serialize an object to JSON
38
String json = mapper.writeValueAsString(myObject);
39
40
// Deserialize JSON to object
41
MyClass obj = mapper.readValue(json, MyClass.class);
42
43
// Create a minimal ObjectMapper (less aggressive configuration)
44
ObjectMapper minimalMapper = Jackson.newMinimalObjectMapper();
45
```
46
47
## Architecture
48
49
The package is built around the central `Jackson` utility class which provides factory methods for creating pre-configured `ObjectMapper` instances. The configuration includes:
50
51
- **Jackson Modules**: Guava, JSR-310 time, JDK8 Optional, parameter names
52
- **Performance Modules**: Afterburner or Blackbird for faster serialization
53
- **Custom Modules**: Fuzzy enum handling, Caffeine cache specs, Guava extras
54
- **Naming Strategy**: Snake case support via annotations
55
- **Subtype Resolution**: Service discovery for polymorphic configurations
56
57
## Capabilities
58
59
### ObjectMapper Factory
60
61
Creates pre-configured Jackson ObjectMapper instances optimized for Dropwizard applications.
62
63
```java { .api }
64
public static ObjectMapper newObjectMapper()
65
public static ObjectMapper newObjectMapper(JsonFactory jsonFactory)
66
public static ObjectMapper newMinimalObjectMapper()
67
```
68
69
[ObjectMapper Factory](./object-mapper-factory.md)
70
71
### Jackson Modules
72
73
Custom Jackson modules for enhanced serialization capabilities including Caffeine cache specs and fuzzy enum handling.
74
75
```java { .api }
76
public class CaffeineModule extends Module
77
public class FuzzyEnumModule extends Module
78
public class GuavaExtrasModule extends Module
79
```
80
81
[Jackson Modules](./jackson-modules.md)
82
83
### Property Naming Strategy
84
85
Annotation-driven property naming that switches between camelCase and snake_case based on class annotations.
86
87
```java { .api }
88
public class AnnotationSensitivePropertyNamingStrategy extends PropertyNamingStrategy
89
public @interface JsonSnakeCase
90
```
91
92
[Property Naming](./property-naming.md)
93
94
### Subtype Discovery
95
96
Service-based discovery mechanism for polymorphic configurations using META-INF/services.
97
98
```java { .api }
99
public class DiscoverableSubtypeResolver extends StdSubtypeResolver
100
public interface Discoverable
101
```
102
103
[Subtype Discovery](./subtype-discovery.md)