Jackson 2.x and 3.x integration module for problem4j-core. Provides easy support for serializing
and deserializing the Problem model using Jackson's ObjectMapper.
Project contains two submodules, problem4j-jackson2 for Jackson 2.x and problem4j-jackson3 for Jackson 3.x. Both
modules have the similar API and functionality, but are compiled against different versions of Jackson (and by extension
against different versions of Java). Choose the one that matches the version of Jackson you are using in your project.
| Module | Jackson Version | Java Baseline |
|---|---|---|
problem4j-jackson2 |
com.fasterxml.jackson.core:jackson-databind:2.x.y |
Java 8 |
problem4j-jackson3 |
tools.jackson.core:jackson-databind:3.x.y |
Java 17 |
Instead of releasing version 2.0, library was split into two modules, because jackson-3.x has different maven
groupId so it's technically possible to have both versions included in the same project. Note that each module is
versioned independently.
- ✅ Seamless JSON serialization of
Problemobjects. - ✅ Accurate deserialization into immutable
Probleminstances. - ✅ Compatible with standard Jackson
ObjectMapper. - ✅ Pluggable via Jackson's
Modulesystem. - ✅ Lightweight, with no external dependencies beyond Jackson and
problem4j-core. - ✅ Support for both Jackson2 and Jackson3.
For problem4j-jackson2 (Jackson 2.x):
import com.fasterxml.jackson.databind.ObjectMapper;
ObjectMapper mapper = new ObjectMapper().registerModule(new ProblemModule());
Problem problem = Problem.builder().title("Bad Request").status(400).detail("not a valid json").build();
String json = mapper.writeValueAsString(problem);
Problem parsed = mapper.readValue(json, Problem.class);Module is included in com.fasterxml.jackson.databind.Module for automatic
service discovery. Registration can also be done with findAndRegisterModules() method or by adding a ProblemMixIn.
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
ObjectMapper mapper = new ObjectMapper().addMixIn(Problem.class, ProblemMixIn.class);For problem4j-jackson3 (Jackson 3.x):
import tools.jackson.databind.json.JsonMapper;
JsonMapper mapper = JsonMapper.builder().addModule(new ProblemJacksonModule()).build();
Problem problem = Problem.builder().title("Bad Request").status(400).detail("not a valid json").build();
String json = mapper.writeValueAsString(problem);
Problem parsed = mapper.readValue(json, Problem.class);Module is included in tools.jackson.databind.JacksonModule for automatic
service discovery. Registration can also be done with findAndAddModules() method or by adding a ProblemJacksonMixIn.
JsonMapper mapper = JsonMapper.builder().findAndAddModules().build();
JsonMapper mapper = JsonMapper.builder().addMixIn(Problem.class, ProblemJacksonMixIn.class).build();Add library as dependency to Maven or Gradle. See the actual versions on Maven Central. Java 8 or
higher is required to use problem4j-jackson library. Java 17 or higher is required to use problem4j-jackson3
library.
The problem4j-jackson modules does not declare jackson-databind as a transitive dependency. You should add
jackson-databind explicitly as your main Jackson dependency.
For problem4j-jackson2 (Jackson 2.x):
- Maven:
<dependencies> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.20.1</version> </dependency> <dependency> <groupId>io.github.problem4j</groupId> <artifactId>problem4j-core</artifactId> <version>1.3.0-RC1</version> </dependency> <dependency> <groupId>io.github.problem4j</groupId> <artifactId>problem4j-jackson2</artifactId> <version>1.3.0-RC1</version> </dependency> </dependencies>
- Gradle (Kotlin DSL):
dependencies { implementation("com.fasterxml.jackson.core:jackson-databind:2.20.0") implementation("io.github.problem4j:problem4j-core:1.3.0-RC1") implementation("io.github.problem4j:problem4j-jackson2:1.3.0-RC1") }
For problem4j-jackson3 (Jackson 3.x):
- Maven:
<dependencies> <dependency> <groupId>tools.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>3.0.3</version> </dependency> <dependency> <groupId>io.github.problem4j</groupId> <artifactId>problem4j-core</artifactId> <version>1.3.0-RC1</version> </dependency> <dependency> <groupId>io.github.problem4j</groupId> <artifactId>problem4j-jackson3</artifactId> <version>1.3.0-RC1</version> </dependency> </dependencies>
- Gradle (Kotlin DSL):
dependencies { implementation("tools.jackson.core:jackson-databind:3.0.3") implementation("io.github.problem4j:problem4j-core:1.3.0-RC1") implementation("io.github.problem4j:problem4j-jackson3:1.3.0-RC1") }
problem4j-core- Core library definingProblemmodel andProblemException.problem4j-jackson- Jackson module for serializing and deserializingProblemobjects.problem4j-spring- Spring modules extendingResponseEntityExceptionHandlerfor handling exceptions and returningProblemresponses.
Expand...
Gradle 9.x+ requires Java 17+ to run, but higher Java versions can also be used.
- Module
problem4j-jacksonis compiled using a Java 8 toolchain, so the produced artifacts are compatible with Java 8. - Module
problem4j-jackson3is compiled using a Java 17 toolchain, so the produced artifacts are compatible with Java 17.
./gradlew buildTo execute tests use test task.
./gradlew testTo format the code according to the style defined in build.gradle.kts rules use spotlessApply
task. Note that building will fail if code is not properly formatted.
./gradlew spotlessApplyTo publish the built artifacts to local Maven repository, run following command, replacing XXXX with the desired
version. By default, the version is derived from git commit hash.
./gradlew -Pversion=XXXX publishToMavenLocal