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

object-mapper-factory.mddocs/

0

# ObjectMapper Factory

1

2

The `Jackson` utility class provides factory methods for creating pre-configured `ObjectMapper` instances optimized for Dropwizard applications.

3

4

## Static Factory Methods

5

6

### newObjectMapper()

7

8

Creates a new ObjectMapper with comprehensive Dropwizard configuration including all modules and optimizations.

9

10

```java { .api }

11

public static ObjectMapper newObjectMapper()

12

```

13

14

**Returns**: Fully configured `ObjectMapper` instance

15

16

**Configuration includes**:

17

- Guava module for Guava collections support

18

- GuavaExtrasModule for CacheBuilderSpec serialization

19

- CaffeineModule for CaffeineSpec serialization

20

- FuzzyEnumModule for permissive enum deserialization

21

- ParameterNamesModule for constructor parameter name preservation

22

- Jdk8Module for Optional and Stream support

23

- JavaTimeModule for JSR-310 time types

24

- Performance module (Afterburner or Blackbird)

25

- AnnotationSensitivePropertyNamingStrategy for snake_case support

26

- DiscoverableSubtypeResolver for polymorphic configurations

27

- Disables FAIL_ON_UNKNOWN_PROPERTIES

28

29

**Usage Example**:

30

```java

31

ObjectMapper mapper = Jackson.newObjectMapper();

32

33

// The mapper is now ready for production use with all optimizations

34

String json = mapper.writeValueAsString(complexObject);

35

MyClass result = mapper.readValue(json, MyClass.class);

36

```

37

38

### newObjectMapper(JsonFactory)

39

40

Creates a new ObjectMapper with a custom JsonFactory and full Dropwizard configuration.

41

42

```java { .api }

43

public static ObjectMapper newObjectMapper(JsonFactory jsonFactory)

44

```

45

46

**Parameters**:

47

- `jsonFactory` (`JsonFactory`, nullable): Custom JsonFactory instance to use

48

49

**Returns**: Fully configured `ObjectMapper` instance using the provided JsonFactory

50

51

**Usage Example**:

52

```java

53

// Create ObjectMapper with custom JsonFactory for YAML processing

54

YAMLFactory yamlFactory = new YAMLFactory();

55

ObjectMapper yamlMapper = Jackson.newObjectMapper(yamlFactory);

56

57

// Or with custom JSON factory settings

58

JsonFactory customFactory = new JsonFactory()

59

.enable(JsonParser.Feature.ALLOW_COMMENTS);

60

ObjectMapper mapper = Jackson.newObjectMapper(customFactory);

61

```

62

63

### newMinimalObjectMapper()

64

65

Creates a minimal ObjectMapper with only essential Dropwizard configuration for less aggressive processing.

66

67

```java { .api }

68

public static ObjectMapper newMinimalObjectMapper()

69

```

70

71

**Returns**: Minimally configured `ObjectMapper` instance

72

73

**Configuration includes**:

74

- GuavaModule for basic Guava collections support

75

- DiscoverableSubtypeResolver for polymorphic configurations

76

- Disables FAIL_ON_UNKNOWN_PROPERTIES

77

78

**Usage Example**:

79

```java

80

// Use when the full configuration is too aggressive for your use case

81

ObjectMapper minimalMapper = Jackson.newMinimalObjectMapper();

82

83

// Still provides essential Dropwizard functionality

84

String json = minimalMapper.writeValueAsString(simpleObject);

85

```

86

87

## Configuration Details

88

89

### Automatic Module Discovery

90

91

The factory methods automatically discover and register Jackson modules available on the classpath:

92

93

- **Afterburner Module**: High-performance bytecode generation (preferred)

94

- **Blackbird Module**: Fallback performance enhancement when Afterburner unavailable

95

96

### Property Handling

97

98

- **Unknown Properties**: Ignored by default (FAIL_ON_UNKNOWN_PROPERTIES disabled)

99

- **Naming Strategy**: Supports both camelCase and snake_case via `@JsonSnakeCase` annotation

100

- **Parameter Names**: Preserved in JSON for constructor parameters

101

102

### Type Support

103

104

- **Java 8 Types**: Optional, Stream, LocalDate, LocalDateTime, Instant, etc.

105

- **Guava Collections**: ImmutableList, ImmutableMap, Multimap, etc.

106

- **Cache Specifications**: CaffeineSpec and CacheBuilderSpec serialization

107

- **Enums**: Fuzzy matching (case-insensitive, handles dashes/periods)