Class JsonApiErrors

java.lang.Object
com.toedter.spring.hateoas.jsonapi.JsonApiErrors

public class JsonApiErrors extends Object
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 Details

  • Method Details

    • withError

      public JsonApiErrors withError(JsonApiError jsonApiError)
      Adds an error to this collection.

      This method returns this to support fluent method chaining.

      Parameters:
      jsonApiError - the error to add; must not be null
      Returns:
      this JsonApiErrors instance for method chaining
      Throws:
      NullPointerException - if jsonApiError is null
    • create

      public static JsonApiErrors create()
      Creates a new empty JsonApiErrors collection.

      This factory method is provided for consistency with other builder patterns in the JSON:API for Spring HATEOASrary.

      Returns:
      a new empty JsonApiErrors instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getErrors

      public List<JsonApiError> getErrors()
      Gets the list of JsonApiError objects contained in this errors collection.
      Returns:
      an unmodifiable view of the error list; will never be null