Class ProblemDetail
- All Implemented Interfaces:
- Serializable
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, for example,
from an @ControllerAdvice such as
ResponseEntityExceptionHandler or
ResponseEntityExceptionHandler.
- Since:
- 6.0
- Author:
- Rossen Stoyanchev, Juergen Hoeller
- See Also:
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedNo-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 SummaryModifier 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, @Nullable 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(@Nullable URI instance) Setter for theproblem instance.voidsetProperties(@Nullable Map<String, Object> properties) Setter for theproperties map.voidsetProperty(String name, @Nullable 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- 
ProblemDetailprotected 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
 
- 
ProblemDetailCopy constructor that a subclass can use to re-create and extend aProblemDetailwith additional properties.
- 
ProblemDetailprotected ProblemDetail()No-arg constructor, for deserialization.
 
- 
- 
Method Details- 
setTypeSetter for theproblem type.By default, this is not set. According to the spec, when not present, the type is assumed to be "about:blank" - Parameters:
- type- the problem type
 
- 
getTypeReturn the configuredproblem type.
- 
setTitleSetter 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
 
- 
getTitleReturn the configuredproblem title.
- 
setStatusSetter for theproblem status.- Parameters:
- httpStatus- the problem status
 
- 
setStatuspublic void setStatus(int status) Setter for theproblem status.- Parameters:
- status- the problem status
 
- 
getStatuspublic int getStatus()Return the status associated with the problem, provided either to the constructor or configured viasetStatus(int).
- 
setDetailSetter for theproblem detail.By default, this is not set. - Parameters:
- detail- the problem detail
 
- 
getDetailReturn the configuredproblem detail.
- 
setInstanceSetter for theproblem instance.By default, when ProblemDetailis returned from an@ExceptionHandlermethod, this is initialized to the request path.- Parameters:
- instance- the problem instance
 
- 
getInstanceReturn the configuredproblem instance.
- 
setPropertySet 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 name
- value- the property value, possibly- nullif the intent is to include a property with its value set to "null"
- See Also:
 
- 
setPropertiesSetter 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
 
- 
getPropertiesReturn 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
- 
toString
- 
initToStringContentReturn a String representation of theProblemDetailfields. Subclasses can override this to append additional fields.
- 
forStatusCreate aProblemDetailinstance with the given status code.
- 
forStatusCreate aProblemDetailinstance with the given status value.
- 
forStatusAndDetailCreate aProblemDetailinstance with the given status and detail.
 
-