Class JsonApiError
java.lang.Object
com.toedter.spring.hateoas.jsonapi.JsonApiError
Represents a single JSON:API error object compliant with the JSON:API specification.
This class provides an immutable representation of an error that can be included in JsonApiErrors collections. Each error object can contain:
- A unique identifier for this specific error occurrence
- Links to additional information (e.g.,
aboutlink) - HTTP status code applicable to the error
- Application-specific error code
- Human-readable summary (title)
- Detailed explanation of the error
- Source information (pointer or parameter causing the error)
- Additional meta information
The class uses Lombok's @With annotation for convenient error building:
JsonApiError error = JsonApiError.create()
.withStatus("404")
.withTitle("Resource not found")
.withDetail("The requested movie does not exist");
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonApiErrorcreate()Creates an emptyJsonApiError.booleangetCode()Gets an application-specific error code, expressed as a string value.Gets a human-readable explanation specific to this occurrence of the problem.getId()Gets a unique identifier for this particular occurrence of the problem.getLinks()Gets a links object containing the following members: about: a link that leads to further details about this particular occurrence of the problem.getMeta()Gets a meta object containing non-standard meta-information about the error.Gets an object containing references to the source of the error, optionally including any of the following members: pointer: a JSON Pointer [RFC6901] to the associated entity in the request document [e.g.Gets the HTTP status code applicable to this problem, expressed as a string value.getTitle()Gets a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.inthashCode()toString()withAboutLink(String aboutLink) Adds an about link to the error.Gets an application-specific error code, expressed as a string value.withDetail(String detail) Gets a human-readable explanation specific to this occurrence of the problem.Gets a unique identifier for this particular occurrence of the problem.Gets a meta object containing non-standard meta-information about the error.withSourceParameter(String sourceParameter) Adds a source parameter to the error.withSourcePointer(String sourcePointer) Adds a source pointer to the error.withStatus(String status) Gets the HTTP status code applicable to this problem, expressed as a string value.Gets a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
-
Constructor Details
-
JsonApiError
public JsonApiError()Creates an emptyJsonApiError.
-
-
Method Details
-
withSourcePointer
Adds a source pointer to the error.- Parameters:
sourcePointer- a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute].- Returns:
- will never be null.
-
withSourceParameter
Adds a source parameter to the error.- Parameters:
sourceParameter- a string indicating which URI query parameter caused the error.- Returns:
- will never be null.
-
withAboutLink
Adds an about link to the error.- Parameters:
aboutLink- the link describing this error- Returns:
- will never be null.
-
create
Creates an emptyJsonApiError.- Returns:
- an empty
JsonApiError.
-
equals
-
hashCode
public int hashCode() -
toString
-
getId
Gets a unique identifier for this particular occurrence of the problem.- Returns:
- will never be null. -- WITHER -- Sets a unique identifier for this particular occurrence of the problem.
-
withId
Gets a unique identifier for this particular occurrence of the problem.- Parameters:
id- the unique identifier of the error.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getLinks
Gets a links object containing the following members: about: a link that leads to further details about this particular occurrence of the problem.- Returns:
- will never be null.
-
getStatus
Gets the HTTP status code applicable to this problem, expressed as a string value.- Returns:
- will never be null. -- WITHER -- Adds the HTTP status code applicable to this problem, expressed as a string value.
-
withStatus
Gets the HTTP status code applicable to this problem, expressed as a string value.- Parameters:
status- the HTTP status code.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getCode
Gets an application-specific error code, expressed as a string value.- Returns:
- will never be null. -- WITHER -- Sets an application-specific error code, expressed as a string value.
-
withCode
Gets an application-specific error code, expressed as a string value.- Parameters:
code- code of the error.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getTitle
Gets a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.- Returns:
- will never be null. -- WITHER -- Sets a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.
-
withTitle
Gets a short, human-readable summary of the problem that SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization.- Parameters:
title- title of the error.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getDetail
Gets a human-readable explanation specific to this occurrence of the problem. Like title, the value can be localized.- Returns:
- will never be null. -- WITHER -- Sets a human-readable explanation specific to this occurrence of the problem. Like title, the value can be localized.
-
withDetail
Gets a human-readable explanation specific to this occurrence of the problem. Like title, the value can be localized.- Parameters:
detail- error detail.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-
getSource
Gets an object containing references to the source of the error, optionally including any of the following members: pointer: a JSON Pointer [RFC6901] to the associated entity in the request document [e.g. "/data" for a primary data object, or "/data/attributes/title" for a specific attribute]. parameter: a string indicating which URI query parameter caused the error.- Returns:
- can be null.
-
getMeta
Gets a meta object containing non-standard meta-information about the error.- Returns:
- will never be null. -- WITHER -- Sets a meta object containing non-standard meta-information about the error.
-
withMeta
Gets a meta object containing non-standard meta-information about the error.- Parameters:
meta- meta object added to the error.- Returns:
- a clone of this object, except with this updated property (returns
thisif an identical value is passed).
-