ProblemDetail.java
package com.fulfilment.application.monolith.exception;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
/**
* RFC 7807 Problem Details response model.
*
* <p>Standard fields:
* <ul>
* <li>{@code type} — URI identifying the problem type</li>
* <li>{@code title} — Short, human-readable summary of the problem type</li>
* <li>{@code status} — HTTP status code</li>
* <li>{@code detail} — Human-readable explanation specific to this occurrence</li>
* </ul>
*
* <p>{@code violations} is included only for validation errors (HTTP 400).
*
* <p>Internal details (stack traces, SQL, class names) are NEVER included.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProblemDetail {
public String type;
public String title;
public int status;
public String detail;
public List<FieldViolation> violations;
public static ProblemDetail of(String type, String title, int status, String detail) {
ProblemDetail p = new ProblemDetail();
p.type = type;
p.title = title;
p.status = status;
p.detail = detail;
return p;
}
/** Represents a single field-level constraint violation (used in 400 responses). */
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class FieldViolation {
public String field;
public String message;
public FieldViolation(String field, String message) {
this.field = field;
this.message = message;
}
}
}