类 ProblemDetail

java.lang.Object
cn.taketoday.http.ProblemDetail

public class ProblemDetail extends Object
Representation for an RFC 7807 problem detail. Includes spec-defined properties, and a properties map for additional, non-standard properties.

For an extended response, an application can add to the properties map. When using the Jackson library, the properties map is expanded as top level JSON properties through the ProblemDetailJacksonMixin.

For an extended response, an application can also create a subclass with additional properties. Subclasses can use the protected copy constructor to re-create an existing ProblemDetail instance as the subclass, e.g. from an @ControllerAdvice such as ResponseEntityExceptionHandler.

从以下版本开始:
4.0 2022/3/2 12:58
作者:
Rossen Stoyanchev, Harry Yang
另请参阅:
  • 字段详细资料

    • BLANK_TYPE

      private static final URI BLANK_TYPE
    • type

      private URI type
    • title

      @Nullable private String title
    • status

      private int status
    • detail

      @Nullable private String detail
    • instance

      @Nullable private URI instance
    • properties

      @Nullable private Map<String,Object> properties
  • 构造器详细资料

    • ProblemDetail

      protected ProblemDetail()
      For deserialization.
    • ProblemDetail

      protected ProblemDetail(int rawStatusCode)
      Protected constructor for subclasses.

      To create a ProblemDetail instance, use static factory methods, forStatus(HttpStatusCode) or forRawStatusCode(int).

      参数:
      rawStatusCode - the response status to use
    • ProblemDetail

      protected ProblemDetail(ProblemDetail other)
      Copy constructor that could be used from a subclass to re-create a ProblemDetail in order to extend it with more fields.
  • 方法详细资料

    • withType

      public ProblemDetail withType(URI type)
      Variant of setType(URI) for chained initialization.
      参数:
      type - the problem type
      返回:
      the same instance
    • withTitle

      public ProblemDetail withTitle(@Nullable String title)
      Variant of setTitle(String) for chained initialization.
      参数:
      title - the problem title
      返回:
      the same instance
    • withStatus

      public ProblemDetail withStatus(HttpStatusCode status)
      Variant of setStatus(int) for chained initialization.
      参数:
      status - the response status for the problem
      返回:
      the same instance
    • withRawStatusCode

      public ProblemDetail withRawStatusCode(int status)
      Variant of setStatus(int) for chained initialization.
      参数:
      status - the response status value for the problem
      返回:
      the same instance
    • withDetail

      public ProblemDetail withDetail(@Nullable String detail)
      Variant of setDetail(String) for chained initialization.
      参数:
      detail - the problem detail
      返回:
      the same instance
    • withInstance

      public ProblemDetail withInstance(@Nullable URI instance)
      Variant of setInstance(URI) for chained initialization.
      参数:
      instance - the problem instance URI
      返回:
      the same instance
    • setType

      public void setType(URI type)
      Setter for the problem type.

      By default, this is BLANK_TYPE.

      参数:
      type - the problem type
      另请参阅:
    • setTitle

      public void setTitle(@Nullable String title)
      Setter for the problem title.

      By default, if not explicitly set and the status is well-known, this is sourced from the HttpStatus.getReasonPhrase().

      参数:
      title - the problem title
      另请参阅:
    • setStatus

      public void setStatus(int status)
      Setter for the problem status.
      参数:
      status - the problem status
      另请参阅:
    • setStatus

      public void setStatus(HttpStatus httpStatus)
      Setter for the problem status.
      参数:
      httpStatus - the problem status
    • setDetail

      public void setDetail(@Nullable String detail)
      Setter for the problem detail.

      By default, this is not set.

      参数:
      detail - the problem detail
      另请参阅:
    • setInstance

      public void setInstance(@Nullable URI instance)
      Setter for the problem instance.

      By default, when ProblemDetail is returned from an @ExceptionHandler method, this is initialized to the request path.

      参数:
      instance - the problem instance
      另请参阅:
    • setProperty

      public void setProperty(String name, @Nullable Object value)
      Set a "dynamic" property to be added to a generic properties map.

      When Jackson JSON is present on the classpath, any properties set here are rendered as top level key-value pairs in the output JSON. Otherwise, they are rendered as a "properties" sub-map.

      参数:
      name - the property name
      value - the property value
      另请参阅:
    • getType

      public URI getType()
      Return the configured problem type.
    • getTitle

      @Nullable public String getTitle()
      Return the configured problem title.
    • getStatus

      public int getStatus()
      Return the status associated with the problem, provided either to the constructor or configured via setStatus(int).
    • getDetail

      @Nullable public String getDetail()
      Return the configured problem detail.
    • getInstance

      @Nullable public URI getInstance()
      Return the configured problem instance.
    • getProperties

      @Nullable public Map<String,Object> getProperties()
      Return a generic map of properties that are not known ahead of time, possibly null if no properties have been added. To add a property, use setProperty(String, Object).

      When Jackson JSON is present on the classpath, the content of this map is unwrapped and rendered as top level key-value pairs in the output JSON. Otherwise, they are rendered as a "properties" sub-map.

      另请参阅:
    • equals

      public boolean equals(@Nullable Object other)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • initToStringContent

      protected String initToStringContent()
      Return a String representation of the ProblemDetail fields. Subclasses can override this to append additional fields.
    • forStatus

      public static ProblemDetail forStatus(HttpStatusCode status)
      Create a ProblemDetail instance with the given status code.
    • forRawStatusCode

      public static ProblemDetail forRawStatusCode(int status)
      Create a ProblemDetail instance with the given status value.
    • forStatusAndDetail

      public static ProblemDetail forStatusAndDetail(HttpStatusCode status, String detail)
      Create a ProblemDetail instance with the given status and detail.