For Jackson 2.x, add the separate jackson-datatype-jdk8 dependency and register Jdk8Module with your ObjectMapper. Jackson 3.x includes Optional support in jackson-databind, so you do not need to add or register that module separately. The right setup depends on your Jackson major version.
Choose the setup for your Jackson version
| Jackson version | Dependency for Optional support | Configuration | Source |
|---|---|---|---|
| 2.x | Add com.fasterxml.jackson.datatype:jackson-datatype-jdk8, aligned with the rest of your Jackson components. |
Register Jdk8Module explicitly, or use automatic module discovery; choose one method. |
FasterXML Java 8 modules README |
| 3.x | Optional support from the former Java 8 module is integrated into jackson-databind. |
Use the Jackson 3.x mapper setup; separate Jdk8Module registration is unnecessary for Optional support. | FasterXML Jackson project |
Configure Optional support in Jackson 2.x
Add the Jdk8 artifact
Include com.fasterxml.jackson.datatype:jackson-datatype-jdk8 as a runtime dependency at a version compatible with your other Jackson components. This is the artifact that provides Jdk8Module; the broader jackson-modules-java8 project is not itself the dependency to add for Optional support.
The FasterXML project recommends keeping Jackson components version-aligned and using its BOM. The project portal listed stable release branches 2.22 and 3.2 when checked in 2026; it lists Jackson 2.22.0, released 31 May 2026, and 3.2.0, released 8 June 2026. These are release facts, not a recommendation to upgrade without checking your application’s compatibility needs. See the Jackson project portal.
Register the module explicitly
For a mapper you configure yourself, register the module before using the mapper:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Jdk8Module());
This enables Jackson 2.x support for Optional, OptionalLong, and OptionalDouble. The Jackson project describes explicit registration as its most common and recommended mechanism: “The most common mechanism (and one recommended by Jackson team) is to explicitly register modules you want.”
Or discover modules automatically
Instead of registering Jdk8Module yourself, ask Jackson to find modules on the classpath:
Rank #2
ObjectMapper mapper = new ObjectMapper();
mapper.findAndRegisterModules();
Discovery uses Java ServiceLoader. Do not combine this call with explicit registration of the same module; the Jackson README cautions against using both approaches. Discovery is not cached, according to the ObjectMapper API documentation, so configure a mapper once and reuse it rather than repeatedly searching for modules.
Use Jackson 3.x without separate Jdk8Module registration
In Jackson 3.x, support for Java 8 types, including Optional, is integrated into jackson-databind. You do not need to add the separate jackson-datatype-jdk8 artifact or register Jdk8Module for this support. Follow the Jackson 3.x mapper construction pattern documented by the project, and keep the Jackson components on compatible versions: FasterXML Jackson project.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Understand what empty Optional means for serialization
For Jackson 2.x, Jdk8Module always considers Optional.empty() empty. Its configureAbsentsAsNulls setting controls whether empty Optional values are also treated as null for serialization filtering. The API documents false as the default and recommendation. If you need to set it explicitly, do so before registering the module:
Jdk8Module jdk8Module = new Jdk8Module()
.configureAbsentsAsNulls(false);
ObjectMapper mapper = new ObjectMapper()
.registerModule(jdk8Module);
Changing this setting later has no effect. It concerns how Optional empty values are treated by serialization inclusion filters; it does not define the JSON meaning of every absent Java property. See the Jdk8Module API documentation for the setting.
Rank #4
When a framework owns the ObjectMapper
If your framework creates the mapper, configure Optional support through that framework’s supported Jackson customization mechanism rather than creating a second mapper that application code does not use. The correct hook depends on the framework; there is no single integration recipe established across frameworks. First confirm the Jackson major version and whether the framework already registers modules.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

