Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Bug report
description: Something broken, confusing, or surprising
labels: [bug]
body:
- type: input
id: version
attributes:
label: Library version
placeholder: e.g. 0.1.0
validations:
required: true
- type: input
id: environment
attributes:
label: Environment
description: Java version, framework (Spring Boot / Jersey / plain Java), relevant dependency versions
placeholder: e.g. Java 21, Spring Boot 4.1, Jackson 3.2
validations:
required: true
- type: textarea
id: expected
attributes:
label: What did you expect to happen?
validations:
required: true
- type: textarea
id: actual
attributes:
label: What happened instead?
description: Include the actual response body or stack trace if there is one
validations:
required: true
- type: textarea
id: reproduction
attributes:
label: Minimal reproduction
description: The smallest code snippet that shows the problem
validations:
required: true
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Feature request
description: An idea for the library
labels: [enhancement]
body:
- type: textarea
id: problem
attributes:
label: What problem would this solve?
description: Describe the situation first — API ideas come second
validations:
required: true
- type: textarea
id: proposal
attributes:
label: What do you propose?
description: Sketch of the API or behavior, if you have one in mind
- type: textarea
id: alternatives
attributes:
label: What have you tried instead?
description: Workarounds you use today, or why existing options fall short
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# What this PR does

<!-- One or two sentences. Link issues with "Fixes #NN" or "Relates to #NN". -->

## How it was checked

- [ ] `./mvnw clean verify` passes locally (JDK 25)
- [ ] New behavior has tests; docs updated alongside
- [ ] No new runtime dependencies (or: new dependency justified below)

## Notes for reviewers

<!-- Anything non-obvious: design trade-offs, alternatives considered, follow-ups. -->
17 changes: 17 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Code of Conduct

This project aims to be a welcoming place for everyone interested in better HTTP error responses in Java.

## The short version

- Be kind and assume good intent. Critique code and ideas, never people.
- No harassment, hate speech, trolling, or unwelcome advances — in issues, pull requests, discussions, or anywhere representing the project.
- Disagreements about design are normal and healthy; keep them technical and specific.

## Enforcement

Unacceptable behavior can be reported privately to [email protected]. Reports are handled confidentially, and maintainers may warn, temporarily limit participation, or permanently remove offenders depending on severity. Retaliation against reporters is itself unacceptable.

## Scope

These rules apply everywhere the project lives: the repository, its issue tracker, pull requests, discussions, and the documentation site.
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contributing

Thanks for your interest in `problem-details-java`. Small, focused contributions beat big ones — a clear bug report is already a contribution.

## How to help

- **Use it and report back.** Real-world usage finds what tests miss: confusing APIs, missing docs, surprising behavior.
- **Report bugs** with a minimal reproduction (input, expected output, actual output, Java and dependency versions).
- **Suggest features** by describing the problem first; API proposals come second.
- **Fix things** via pull request (see below).

## Working on the code

Prerequisites: JDK 25 (pinned in `.sdkmanrc`) and the Maven wrapper — no other toolchain needed.

```sh
./mvnw clean verify # full build, tests, format check
./mvnw spotless:apply # fix formatting (Google Java Style, enforced in CI)
```

Conventions that matter:

- Java 17 is the compatibility floor: no newer language features or APIs in main code.
- `problem-details-core` stays dependency-free — framework or serialization imports there are a design discussion first, never a drive-by.
- Public API needs Javadoc, and behavior changes need tests. The bar is in `AGENTS.md`.
- One logical change per pull request, with tests and docs updated alongside.

## Pull requests

1. Fork, branch from `main` (`feat/...`, `fix/...`, `docs/...`, `chore/...`).
2. Keep the change tight; explain non-obvious design calls in the PR body.
3. Make sure `./mvnw clean verify` and the format check pass — CI runs both on JDK 17 and 25.
4. Maintainers merge with squash once CI is green and review is done.

## Releases

Only maintainers cut releases; the process is documented in `AGENTS.md`. If you need something released, open an issue and say so.
113 changes: 51 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,78 @@
# problem-details-java

A framework-agnostic Java implementation of [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457), *Problem Details for HTTP APIs*.
[![Build](https://github.com/othmaneataallah/problem-details-java/actions/workflows/build.yml/badge.svg)](https://github.com/othmaneataallah/problem-details-java/actions)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.othmaneataallah/problem-details-core)](https://central.sonatype.com/search?q=g%3Aio.github.othmaneataallah)
[![License](https://img.shields.io/github/license/othmaneataallah/problem-details-java)](LICENSE)
[![Java](https://img.shields.io/badge/Java-17%2B-blue)](https://adoptium.net/)

The project provides a lightweight and extensible implementation with a dependency-free core and optional modules for JSON and XML serialization, a problem-type registry, and Spring and JAX-RS integrations.

## Status

All planned modules are implemented on `main`. The project versions as `0.1.0-SNAPSHOT` and has **not** been published to Maven Central yet; publishing is deliberately deferred until the codebase and testing are finalized.

## Modules

| Artifact | Description |
|-----------------------------------|-----------------------------------------------------------------------------------------------|
| `problem-details-core` | Dependency-free problem details model and API: immutable `ProblemDetail` + builder, typed extension keys (`ProblemDetailKey<T>`), `ProblemDetailException` |
| `problem-details-jackson` | JSON serialization (`application/problem+json`) on Jackson 3 |
| `problem-details-xml` | XML serialization (`application/problem+xml`, RFC 9457 Appendix B) using only the JDK |
| `problem-details-registry` | IANA problem-type constants/helpers, `ProblemTypeRegistry`, custom problem-type support |
| `problem-details-spring` | Thin Spring MVC/WebFlux integration (Spring 7): converter plus a stack-agnostic `@ControllerAdvice` |
| `problem-details-jaxrs` | JAX-RS integration (Jakarta REST 4): `ExceptionMapper` and `MessageBodyWriter` for both media types |

Group ID for all artifacts: `io.github.othmaneataallah`.

## Usage

Core model — no dependencies beyond the core artifact:
Ever returned an error from a Java API and wished every service did it the same way? [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457) defines that way — a standard `type`, `title`, `status`, `detail`, and `instance` for HTTP errors. This library implements it for Java, so your APIs speak the same error language as everyone else's.

```java
ProblemDetail problem = ProblemDetail.builder()
.type("https://example.com/probs/out-of-credit")
.title("You do not have enough credit.")
.status(403)
.detail("Your current balance is 30, but that costs 50.")
.build();
throw new ProblemDetailException(
ProblemDetail.builder()
.type("https://example.com/probs/out-of-credit")
.title("You do not have enough credit.")
.status(403)
.detail("Your current balance is 30, but that costs 50.")
.build());
```

JSON with Jackson 3:

```java
JsonMapper mapper = JsonMapper.builder()
.addModule(new ProblemDetailsModule())
.build();
String json = mapper.writeValueAsString(problem); // application/problem+json
```
Your clients get a proper `application/problem+json` response — no custom error formats to invent, document, or debug.

XML with the JDK only:
## Start here

```java
String xml = ProblemXml.toXml(problem); // application/problem+xml
```xml
<dependency>
<groupId>io.github.othmaneataallah</groupId>
<artifactId>problem-details-core</artifactId>
<version>0.1.0</version>
</dependency>
```

Spring (register the advice explicitly, e.g. `@Import(ProblemDetailAdvice.class)`):

```java
throw new ProblemDetailException(problem); // rendered as application/problem+json
```
Then follow the [Quickstart](https://othmaneataallah.github.io/problem-details-java/quickstart/) — five minutes from empty project to first error response. Full guides live on the [documentation site](https://othmaneataallah.github.io/problem-details-java/).

See each module's `package-info.java` and the Javadoc for details, including extension members, the registry, and leniency rules.
## What's inside

## Requirements
| Module | What it does |
|---|---|
| `problem-details-core` | The model itself. No dependencies, no framework needed. |
| `problem-details-jackson` | Reads and writes `application/problem+json` (Jackson 3). |
| `problem-details-xml` | Reads and writes `application/problem+xml` (JDK only, nothing extra to install). |
| `problem-details-registry` | Reusable, documented error types instead of inventing your own. |
| `problem-details-spring` | One annotation and Spring MVC/WebFlux apps render errors correctly. |
| `problem-details-jaxrs` | Same for Jakarta REST, in JSON and XML. |

To **use** the library: Java 17+.
Custom fields (balances, validation errors, anything yours) are first-class and type-safe — see [Core concepts](https://othmaneataallah.github.io/problem-details-java/core/).

To **build** it:
## See it running

- JDK 25 (pinned in `.sdkmanrc`; artifacts still target Java 17)
- Maven via the wrapper: `./mvnw clean verify`
Two runnable demos ship in [`demo/`](demo/) — real apps using the released library, each with a script that checks every endpoint:

## Building and testing
- [`demo/spring-boot`](demo/spring-boot) — Spring Boot app: full errors, validation lists, registry use, status fallbacks.
- [`demo/jersey`](demo/jersey) — Jersey/Grizzly app: JSON *and* XML responses from the same code.

```sh
./mvnw clean verify # full build, tests, and format check (JDK 21+)
./mvnw spotless:apply # auto-fix formatting (google-java-format)
cd demo/spring-boot
../../mvnw spring-boot:run # in one shell
./verify.sh # in another — all checks should pass
```

CI runs the same verification on JDK 17 and JDK 25. Java formatting is enforced by Spotless; see `AGENTS.md` for contributor conventions.
## Reference

## IntelliJ IDEA setup
- [Documentation site](https://othmaneataallah.github.io/problem-details-java/) — guides, compatibility notes, FAQ.
- [API docs (Javadoc)](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-core) — per module: `problem-details-core`, `problem-details-jackson`, `problem-details-xml`, `problem-details-registry`, `problem-details-spring`, `problem-details-jaxrs`.
- [Changelog](CHANGELOG.md).

No committed run configurations are needed (this is a library, not an application):
## Building it yourself

You need JDK 25 to build (the code itself runs on Java 17+):

```sh
./mvnw clean verify
```

1. Open the project and set the Project SDK to JDK 25.
2. Under *Settings → Build Tools → Maven*, use the Maven wrapper.
3. Run the build from the Maven tool window (`clean verify`), or create personal (uncommitted) Maven run configurations for `clean verify` and `spotless:apply`.
4. Tests also run natively (right-click a test or class). For exact Google Java Style formatting, install the google-java-format plugin matching the version pinned in the root `pom.xml`, or run `./mvnw spotless:apply` before committing.
Want to help? Read [CONTRIBUTING.md](CONTRIBUTING.md) — bug reports with reproductions are the most valuable contribution.

## License

Licensed under the Apache License, Version 2.0 — see [LICENSE](LICENSE).
Apache License 2.0 — see [LICENSE](LICENSE).
16 changes: 16 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Security Policy

This library deals with error responses, which sit close to information disclosure risks — reports are taken seriously.

## Reporting a vulnerability

**Do not open a public issue.** Email [email protected] with:

- What is affected (module, version) and what an attacker could achieve.
- Steps to reproduce, ideally as a small test or snippet.

You will get a response within a few days. Once a fix is agreed, it ships as a normal release and the reporter is credited unless they prefer otherwise.

## Supported versions

Only the latest release line receives security fixes. There are no long-term-support branches at this time.
12 changes: 12 additions & 0 deletions docs-site/docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# API reference

The guides on this site show the common paths. For everything else — every class, method, and contract — read the Javadoc:

- [`problem-details-core`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-core) — `ProblemDetail`, `ProblemDetailKey`, `ProblemDetailException`
- [`problem-details-jackson`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-jackson) — `ProblemDetailsModule`, serializer, deserializer
- [`problem-details-xml`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-xml) — `ProblemXml`
- [`problem-details-registry`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-registry) — `ProblemType`, `ProblemTypeRegistry`
- [`problem-details-spring`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-spring) — `SpringProblemDetails`, `ProblemDetailAdvice`
- [`problem-details-jaxrs`](https://javadoc.io/doc/io.github.othmaneataallah/problem-details-jaxrs) — writer and exception mapper

These pages are generated from each release automatically. If a link above doesn't resolve yet, the newest release is still propagating — try again shortly.
29 changes: 14 additions & 15 deletions docs-site/docs/compatibility.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Compatibility

Minimums that are tested, not guessed — CI builds and tests every change on both JDK 17 and JDK 25.
Tested combinations — CI builds and tests every change on JDK 17 and 25, so these are facts, not hopes.

| Concern | Version |
|------------------|----------------------------------------------------------------|
| Your runtime | Java 17+ |
| Build JDK | 25 (artifacts target Java 17) |
| JSON | Jackson 3 (`tools.jackson.core:jackson-databind`) |
| XML | JDK only — no third-party dependency |
| Spring module | Spring Framework 7 (`spring-web`); MVC and WebFlux both covered |
| JAX-RS module | Jakarta REST 4 API (`provided` scope) |
| Tests | JUnit 6 + AssertJ |
| You need | Version |
|-----------------------|----------------------------------------------------------------|
| Java to run it | 17 or newer |
| JSON | Jackson 3 |
| XML | Nothing extra (JDK only) |
| Spring module | Spring Framework 7, MVC or WebFlux |
| JAX-RS module | Jakarta REST 4 (your runtime provides it) |
| Tests (contributors) | JUnit 6 + AssertJ |

Notes and honest limits:
A few straight answers:

- **Jackson 2 is not supported.** Jackson 3 is the current major line and Spring Boot 4's default; Jackson 2 support is deprecated upstream. The JSON module is Jackson 3 only.
- **Spring 6 / Boot 3 are untested.** The Spring module builds against Spring 7, whose baseline is still Java 17 — but Boot 3's line is end-of-life, so upgrade rather than backport.
- **Jakarta REST 3.x runtimes** will likely run the JAX-RS module (the APIs used are unchanged), but only Jakarta 4 is tested.
- Snapshots (`0.2.0-SNAPSHOT`) are never published; releases are cut as version tags and staged on Maven Central.
- **Jackson 2? No.** Jackson 3 is the current major line and what Spring Boot 4 ships. Jackson 2 support is deprecated upstream — staying on it would date the library on arrival.
- **Spring Boot 3? Untested, and its line is end-of-life.** The Spring module builds against Spring 7, which still runs on Java 17, so upgrading Boot is the only sane path.
- **Jakarta REST 3.x?** Probably works (the APIs used haven't changed), but only version 4 is tested.
- **Snapshots?** Never published. Releases come as version tags on Maven Central.
Loading
Loading