Class 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
.
- Since:
- 6.0
- Author:
- Rossen Stoyanchev
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
No-arg constructor, for deserialization.protected
ProblemDetail
(int rawStatusCode) Protected constructor for subclasses.protected
ProblemDetail
(ProblemDetail other) Copy constructor that a subclass can use to re-create and extend aProblemDetail
with additional properties. -
Method Summary
Modifier and TypeMethodDescriptionstatic ProblemDetail
forStatus
(int status) Create aProblemDetail
instance with the given status value.static ProblemDetail
forStatus
(HttpStatusCode status) Create aProblemDetail
instance with the given status code.static ProblemDetail
forStatusAndDetail
(HttpStatusCode status, String detail) Create aProblemDetail
instance 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, possiblynull
if no properties have been added.int
Return 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
.protected String
Return a String representation of theProblemDetail
fields.void
Setter for theproblem detail
.void
setInstance
(URI instance) Setter for theproblem instance
.void
setProperty
(String name, Object value) Set a "dynamic" property to be added to a genericproperties map
.void
setStatus
(int status) Setter for theproblem status
.void
setStatus
(HttpStatus httpStatus) Setter for theproblem status
.void
Setter for theproblem title
.void
Setter for theproblem type
.toString()
-
Constructor Details
-
ProblemDetail
protected ProblemDetail(int rawStatusCode) Protected constructor for subclasses.To create a
ProblemDetail
instance, use static factory methods,forStatus(HttpStatusCode)
orforStatus(int)
.- Parameters:
rawStatusCode
- the response status to use
-
ProblemDetail
Copy constructor that a subclass can use to re-create and extend aProblemDetail
with additional properties. -
ProblemDetail
protected ProblemDetail()No-arg constructor, for deserialization.
-
-
Method Details
-
setType
Setter for theproblem type
.By default, this is
BLANK_TYPE
.- Parameters:
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()
.- Parameters:
title
- the problem title
-
setStatus
Setter for theproblem status
.- Parameters:
httpStatus
- the problem status
-
setStatus
public void setStatus(int status) Setter for theproblem status
.- Parameters:
status
- the problem status
-
setDetail
Setter for theproblem detail
.By default, this is not set.
- Parameters:
detail
- the problem detail
-
setInstance
Setter for theproblem instance
.By default, when
ProblemDetail
is returned from an@ExceptionHandler
method, this is initialized to the request path.- Parameters:
instance
- the problem instance
-
setProperty
Set a "dynamic" property to be added to a genericproperties map
.- Parameters:
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, possiblynull
if no properties have been added. To add a property, usesetProperty(String, Object)
. -
toString
-
initToStringContent
Return a String representation of theProblemDetail
fields. Subclasses can override this to append additional fields. -
forStatus
Create aProblemDetail
instance with the given status code. -
forStatus
Create aProblemDetail
instance with the given status value. -
forStatusAndDetail
Create aProblemDetail
instance with the given status and detail.
-