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
or
ResponseEntityExceptionHandler
.
- Since:
- 6.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- 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 TypeMethodDescriptionboolean
static 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
.int
hashCode()
protected String
Return a String representation of theProblemDetail
fields.void
Setter for theproblem detail
.void
setInstance
(URI instance) Setter for theproblem instance
.void
setProperties
(Map<String, Object> properties) Setter for theproperties map
.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
-
getType
Return the configuredproblem 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
-
getTitle
Return the configuredproblem 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
-
getStatus
public int getStatus()Return the status associated with the problem, provided either to the constructor or configured viasetStatus(int)
. -
setDetail
Setter for theproblem detail
.By default, this is not set.
- Parameters:
detail
- the problem detail
-
getDetail
Return the configuredproblem 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
-
getInstance
Return the configuredproblem 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.- Parameters:
name
- the property namevalue
- the property value, possiblynull
if the intent is to include a property with its value set to "null"- See Also:
-
setProperties
Setter for theproperties map
.By default, this is not set.
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.- Parameters:
properties
- the properties map- Since:
- 6.0.14
-
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)
.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.- See Also:
-
equals
-
hashCode
public int hashCode() -
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.
-