Class Problem

java.lang.Object
org.apache.juneau.bean.rfc7807.Problem

@Marshalled public class Problem extends Object
RFC 7807 — Problem Details for HTTP APIs bean.

Represents the canonical application/problem+json document. The five standard members defined by §3.1 are modelled as typed properties; arbitrary §3.2 extension members flatten into the top-level JSON object via a @BeanProp("*") triplet.

Example:

Problem problem = new Problem() .setType(new URI("https://example.com/probs/out-of-credit")) .setTitle("You do not have enough credit.") .setStatus(403) .setDetail("Your current balance is 30, but that costs 50.") .setInstance(new URI("/account/12345/msgs/abc")) .set("balance", 30) .set("accounts", list("/account/12345", "/account/67890")); String json = JsonSerializer.DEFAULT.write(problem);

Notes:
  • The type field is nullable. getType() returns the raw value (possibly null); getTypeOrDefault() returns the spec default "about:blank" per RFC 7807 §3.1 when the field is unset. The field is never eagerly defaulted, so a fresh Problem round-trips without a synthetic "type":"about:blank" on the wire.
  • RFC 7807 was obsoleted by RFC 9457 in July 2023, but the data model and the application/problem+json IANA registration are unchanged.
See Also:
  • Field Details

    • DEFAULT_TYPE

      public static final URI DEFAULT_TYPE
      The default type URI defined by RFC 7807 §3.1 for problem documents that omit the type member.
  • Constructor Details

  • Method Details

    • fromStatus

      public static Problem fromStatus(int status, String title, String detail)
      Convenience factory for the common "build a problem from a status code + title + detail" call site.

      Populates only the status, title, and detail members. Callers wire from Throwables or HTTP exception types themselves — for example:

      Problem.fromStatus(e.getStatusCode(), e.getStatusLine().getReasonPhrase(), e.getMessage());

      Parameters:
      status - The HTTP status code (e.g. 404).
      title - A short, human-readable summary of the problem type. Can be null to leave the title unset.
      detail - A human-readable explanation specific to this occurrence. Can be null to leave the detail unset.
      Returns:
      A new Problem populated with the supplied values.
    • getType

      public URI getType()
      The type URI that identifies the problem type.

      Returns the raw field value, which may be null when the type member is absent. Use getTypeOrDefault() to get the spec default "about:blank" for absent values.

      Returns:
      The type URI, or null if not set.
    • getTypeOrDefault

      Returns the type URI, defaulting to DEFAULT_TYPE ("about:blank") per RFC 7807 §3.1 when the field is null.

      The underlying field is left untouched, so this method never causes a synthetic "type":"about:blank" to appear on the wire.

      Returns:
      The type URI, never null.
    • setType

      public Problem setType(URI value)
      Sets the type URI.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • getTitle

      public String getTitle()
      The title — a short, human-readable summary of the problem type.
      Returns:
      The title, or null if not set.
    • setTitle

      public Problem setTitle(String value)
      Sets the title.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • getStatus

      public Integer getStatus()
      The status — the HTTP status code originally generated by the origin server for this occurrence.

      Modelled as Integer (boxed) because RFC 7807 declares status as OPTIONAL.

      Returns:
      The status code, or null if not set.
    • setStatus

      public Problem setStatus(Integer value)
      Sets the status HTTP status code.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • getDetail

      public String getDetail()
      The detail — a human-readable explanation specific to this occurrence of the problem.
      Returns:
      The detail, or null if not set.
    • setDetail

      public Problem setDetail(String value)
      Sets the detail.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • getInstance

      public URI getInstance()
      The instance URI that identifies the specific occurrence of the problem.
      Returns:
      The instance URI, or null if not set.
    • setInstance

      public Problem setInstance(URI value)
      Sets the instance URI.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object.
    • extraKeys

      @BeanProp("*") public Set<String> extraKeys()
      Generic extension-member keyset.
      Returns:
      All extension keys on this problem. Never null.
    • get

      @BeanProp("*") public Object get(String property)
      Generic extension-member getter.

      Used by the bean framework to read arbitrary §3.2 extension members that flatten into the top-level JSON object.

      Parameters:
      property - The property name to retrieve. Can be null (a null key simply resolves to no value).
      Returns:
      The property value, or null if the property does not exist.
    • set

      @BeanProp("*") public Problem set(String property, Object value)
      Generic extension-member setter.

      Used by the bean framework to set arbitrary §3.2 extension members. The extension map is lazily initialised on first use.

      Parameters:
      property - The property name to set. Can be null (LinkedHashMap tolerates a null key).
      value - The new value for the property. Can be null (stored as null).
      Returns:
      This object.