@@ -20,18 +20,21 @@ It is intended to be used as a **foundation** for other libraries or application
2020
2121## Features
2222
23- - ✅ Immutable ` Problem ` data model
24- - ✅ Dedicated unchecked ` ProblemException ` to be used in error handling
25- - ✅ Builder pattern for fluent construction
26- - ✅ Serializable and easy to log or format
27- - ✅ HTTP-agnostic (no external dependencies)
23+ - ✅ Immutable ` Problem ` data model.
24+ - ✅ Dedicated unchecked ` ProblemException ` to be used in error handling.
25+ - ✅ Builder pattern for fluent construction.
26+ - ✅ Annotation ` @ProblemMapping ` and ` ProblemMapper ` to allow declarative approach in converting exception instances
27+ into ` Problem ` objects.
28+ - ✅ Builder pattern for fluent construction.
29+ - ✅ Serializable and easy to log or format.
30+ - ✅ HTTP-agnostic (no external dependencies).
2831- ✅ Follows [ RFC 7807] [ rfc7807 ] semantics:
29- - ` type ` (URI)
30- - ` title ` (short summary)
31- - ` status ` (numeric code)
32- - ` detail ` (detailed description)
33- - ` instance ` (URI to the specific occurrence)
34- - custom field extensions
32+ - ` type ` (URI),
33+ - ` title ` (short summary),
34+ - ` status ` (numeric code),
35+ - ` detail ` (detailed description),
36+ - ` instance ` (URI to the specific occurrence),
37+ - custom field extensions.
3538
3639## Example
3740
@@ -50,6 +53,32 @@ Problem problem =
5053throw new ProblemException (problem);
5154```
5255
56+ ``` java
57+ import io.github.problem4j.core.ProblemMapping ;
58+ import io.github.problem4j.core.ProblemMapper ;
59+
60+ @ProblemMapping (
61+ type = " https://example.org/probs/tests" ,
62+ title = " Test problem" ,
63+ status = 400 ,
64+ detail = " failed: {message}" ,
65+ extensions = {" subject" })
66+ public class MessageException extends RuntimeException {
67+
68+ private final String subject;
69+
70+ public MessageException (String subject , String message ) {
71+ super (message);
72+ this . subject = subject;
73+ }
74+ }
75+
76+ MessageException ex = new MessageException (" sub" , " boom" );
77+
78+ ProblemMapper mapper = ProblemMapper . create();
79+ Problem problem = mapper. toProblemBuilder(ex). build();
80+ ```
81+
5382## Usage
5483
5584Add library as dependency to Maven or Gradle. See the actual versions on [ Maven Central] [ maven-central ] . ** Java 8** or
0 commit comments