Part of
problem4j
package of libraries.
This library provides a minimal, framework-agnostic Java model of the RFC 7807 "Problem Details" object, with
an immutable Problem
class and a fluent ProblemBuilder
for convenient construction.
It is intended to be used as a foundation for other libraries or applications that add framework-specific behavior (e.g. Jackson, Spring).
- ✅ Immutable
Problem
data model - ✅ Dedicated unchecked
ProblemException
to be used in error handling - ✅ Builder pattern for fluent construction
- ✅ Serializable and easy to log or format
- ✅ HTTP-agnostic (no external dependencies)
- ✅ Follows RFC 7807 semantics:
type
(URI)title
(short summary)status
(numeric code)detail
(detailed description)instance
(URI to the specific occurrence)- custom field extensions
import io.github.malczuuu.problem4j.core.Problem;
import io.github.malczuuu.problem4j.core.ProblemException;
public class ExampleClass {
public void method() {
Problem problem =
Problem.builder()
.type("https://example.com/errors/invalid-request")
.title("Invalid Request")
.status(400)
.detail("not a valid json")
.instance("https://example.com/instances/1234")
.build();
throw new ProblemException(problem);
}
}
Add library as dependency to Maven or Gradle. See the actual versions on Maven Central. Java 8 or higher is required to use this library.
- Maven:
<dependencies> <dependency> <groupId>io.github.malczuuu.problem4j</groupId> <artifactId>problem4j-core</artifactId> <version>1.1.0</version> </dependency> </dependencies>
- Gradle (Groovy or Kotlin DSL):
dependencies { implementation("io.github.malczuuu.problem4j:problem4j-core:1.1.0") }
problem4j
- Documentation repository.problem4j-core
- Core library definingProblem
model andProblemException
.problem4j-jackson
- Jackson module for serializing and deserializingProblem
objects.problem4j-spring-web
- Spring Web module extendingResponseEntityExceptionHandler
for handling exceptions and returningProblem
responses.