Skip to content

malczuuu/problem4j-core

Repository files navigation

Problem4J Core

JitPack Build Status

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).

Features

  • ✅ 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

Example

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);

Usage

This library is available through Jitpack repository. Add it along with repository in your dependency manager.

// build.gradle

repositories {
    // ...
    maven { url "https://jitpack.io/" }
}

dependencies {
    // ...
    implementation("com.github.malczuuu:problem4j-core:<version>")
}