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
ConstructorsModifierConstructorDescriptionprotectedNo-arg constructor, for deserialization.protectedProblemDetail(int rawStatusCode) Protected constructor for subclasses.protectedProblemDetail(ProblemDetail other) Copy constructor that a subclass can use to re-create and extend aProblemDetailwith additional properties. -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic ProblemDetailforStatus(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.voidsetProperties(Map<String, Object> properties) Setter for theproperties map.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()
-
Constructor Details
-
ProblemDetail
protected ProblemDetail(int rawStatusCode) Protected constructor for subclasses.To create a
ProblemDetailinstance, 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 aProblemDetailwith 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
ProblemDetailis returned from an@ExceptionHandlermethod, 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, possiblynullif 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, 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.- See Also:
-
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. -
forStatus
Create aProblemDetailinstance with the given status value. -
forStatusAndDetail
Create aProblemDetailinstance with the given status and detail.
-