Class JsonApiErrors
java.lang.Object
com.toedter.spring.hateoas.jsonapi.JsonApiErrors
Collection of JSON:API error objects for building compliant error responses.
This class represents the top-level errors member of a JSON:API document, containing
one or more JsonApiError objects. According to the JSON:API specification, a document
must contain either data, errors, or meta at the top level, and
errors must not coexist with data.
Usage example:
JsonApiErrors errors = JsonApiErrors.create()
.withError(JsonApiError.create()
.withStatus("404")
.withTitle("Resource not found"))
.withError(JsonApiError.create()
.withStatus("403")
.withTitle("Forbidden"));
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an emptyJsonApiErrorscollection.JsonApiErrors(JsonApiError jsonApiError) Creates aJsonApiErrorscollection with an initial error. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonApiErrorscreate()Creates a new emptyJsonApiErrorscollection.Gets the list ofJsonApiErrorobjects contained in this errors collection.toString()withError(JsonApiError jsonApiError) Adds an error to this collection.
-
Constructor Details
-
JsonApiErrors
public JsonApiErrors()Creates an emptyJsonApiErrorscollection.Use
withError(JsonApiError)to add errors to the collection. -
JsonApiErrors
Creates aJsonApiErrorscollection with an initial error.- Parameters:
jsonApiError- the initial error to add; must not be null- Throws:
NullPointerException- ifjsonApiErroris null
-
-
Method Details
-
withError
Adds an error to this collection.This method returns
thisto support fluent method chaining.- Parameters:
jsonApiError- the error to add; must not be null- Returns:
- this
JsonApiErrorsinstance for method chaining - Throws:
NullPointerException- ifjsonApiErroris null
-
create
Creates a new emptyJsonApiErrorscollection.This factory method is provided for consistency with other builder patterns in the JSON:API for Spring HATEOASrary.
- Returns:
- a new empty
JsonApiErrorsinstance
-
toString
-
getErrors
Gets the list ofJsonApiErrorobjects contained in this errors collection.- Returns:
- an unmodifiable view of the error list; will never be null
-