类 ProblemDetail
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
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器限定符构造器说明protectedFor deserialization.protectedProblemDetail(int rawStatusCode) Protected constructor for subclasses.protectedProblemDetail(ProblemDetail other) Copy constructor that could be used from a subclass to re-create aProblemDetailin order to extend it with more fields. -
方法概要
修饰符和类型方法说明booleanstatic ProblemDetailforRawStatusCode(int status) Create aProblemDetailinstance with the given status value.static ProblemDetailforStatus(HttpStatusCode status) Create aProblemDetailinstance with the given status code.static ProblemDetailforStatusAndDetail(HttpStatusCode status, String detail) Create aProblemDetailinstance with the given status and detail.Return the configuredproblem detail.Return the configuredproblem instance.Return a generic map of properties that are not known ahead of time, possiblynullif no properties have been added.intReturn the status associated with the problem, provided either to the constructor or configured viasetStatus(int).getTitle()Return the configuredproblem title.getType()Return the configuredproblem type.inthashCode()protected StringReturn a String representation of theProblemDetailfields.voidSetter for theproblem detail.voidsetInstance(URI instance) Setter for theproblem instance.voidsetProperty(String name, Object value) Set a "dynamic" property to be added to a genericproperties map.voidsetStatus(int status) Setter for theproblem status.voidsetStatus(HttpStatus httpStatus) Setter for theproblem status.voidSetter for theproblem title.voidSetter for theproblem type.toString()withDetail(String detail) Variant ofsetDetail(String)for chained initialization.withInstance(URI instance) Variant ofsetInstance(URI)for chained initialization.withRawStatusCode(int status) Variant ofsetStatus(int)for chained initialization.withStatus(HttpStatusCode status) Variant ofsetStatus(int)for chained initialization.Variant ofsetTitle(String)for chained initialization.Variant ofsetType(URI)for chained initialization.
-
字段详细资料
-
BLANK_TYPE
-
type
-
title
-
status
private int status -
detail
-
instance
-
properties
-
-
构造器详细资料
-
ProblemDetail
protected ProblemDetail()For deserialization. -
ProblemDetail
protected ProblemDetail(int rawStatusCode) Protected constructor for subclasses.To create a
ProblemDetailinstance, use static factory methods,forStatus(HttpStatusCode)orforRawStatusCode(int).- 参数:
rawStatusCode- the response status to use
-
ProblemDetail
Copy constructor that could be used from a subclass to re-create aProblemDetailin order to extend it with more fields.
-
-
方法详细资料
-
withType
Variant ofsetType(URI)for chained initialization.- 参数:
type- the problem type- 返回:
- the same instance
-
withTitle
Variant ofsetTitle(String)for chained initialization.- 参数:
title- the problem title- 返回:
- the same instance
-
withStatus
Variant ofsetStatus(int)for chained initialization.- 参数:
status- the response status for the problem- 返回:
- the same instance
-
withRawStatusCode
Variant ofsetStatus(int)for chained initialization.- 参数:
status- the response status value for the problem- 返回:
- the same instance
-
withDetail
Variant ofsetDetail(String)for chained initialization.- 参数:
detail- the problem detail- 返回:
- the same instance
-
withInstance
Variant ofsetInstance(URI)for chained initialization.- 参数:
instance- the problem instance URI- 返回:
- the same instance
-
setType
Setter for theproblem type.By default, this is
BLANK_TYPE.- 参数:
type- the problem type- 另请参阅:
-
setTitle
Setter for theproblem 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 theproblem status.- 参数:
status- the problem status- 另请参阅:
-
setStatus
Setter for theproblem status.- 参数:
httpStatus- the problem status
-
setDetail
Setter for theproblem detail.By default, this is not set.
- 参数:
detail- the problem detail- 另请参阅:
-
setInstance
Setter for theproblem instance.By default, when
ProblemDetailis returned from an@ExceptionHandlermethod, this is initialized to the request path.- 参数:
instance- the problem instance- 另请参阅:
-
setProperty
Set a "dynamic" property to be added to a genericproperties 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 namevalue- the property value- 另请参阅:
-
getType
Return the configuredproblem type. -
getTitle
Return the configuredproblem title. -
getStatus
public int getStatus()Return the status associated with the problem, provided either to the constructor or configured viasetStatus(int). -
getDetail
Return the configuredproblem detail. -
getInstance
Return the configuredproblem instance. -
getProperties
Return a generic map of properties that are not known ahead of time, possiblynullif no properties have been added. To add a property, usesetProperty(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
-
hashCode
public int hashCode() -
toString
-
initToStringContent
Return a String representation of theProblemDetailfields. Subclasses can override this to append additional fields. -
forStatus
Create aProblemDetailinstance with the given status code. -
forRawStatusCode
Create aProblemDetailinstance with the given status value. -
forStatusAndDetail
Create aProblemDetailinstance with the given status and detail.
-