java.lang.Object
org.springframework.hateoas.mediatype.problem.Problem
Direct Known Subclasses:
Problem.ExtendedProblem

public class Problem extends Object
Encapsulation of an RFC-7807 Problem code. While it complies out-of-the-box, it may also be extended to support domain-specific details.
Author:
Greg Turnquist, Oliver Drotbohm
  • Constructor Details

    • Problem

      public Problem(@Nullable URI type, @Nullable String title, @Nullable Integer status, @Nullable String detail, @Nullable URI instance)
    • Problem

      protected Problem(@Nullable URI type, @Nullable String title, @Nullable org.springframework.http.HttpStatus status, @Nullable String detail, @Nullable URI instance)
  • Method Details

    • create

      public static Problem create()
      Returns an empty Problem instance.
      Returns:
      an empty Problem instance.
    • create

      public static <T> Problem.ExtendedProblem<T> create(T payload)
      Returns an Problem.ExtendedProblem with the given payload as additional properties.
      Type Parameters:
      T -
      Parameters:
      payload - must not be null.
      Returns:
    • statusOnly

      public static Problem statusOnly(org.springframework.http.HttpStatus status)
      Returns a Problem instance with the given HttpStatus and defaults as defined in RFC7807.
      Parameters:
      status - must not be null.
      Returns:
      See Also:
    • withType

      public Problem withType(@Nullable URI type)
      Create a new Problem by copying its attributes and replacing the type.
      Parameters:
      type -
      Returns:
    • withTitle

      public Problem withTitle(@Nullable String title)
      Create a new Problem by copying its attributes and replacing the title.
      Parameters:
      title -
      Returns:
    • withStatus

      public Problem withStatus(@Nullable org.springframework.http.HttpStatus status)
      Create a new Problem by copying its attributes and replacing the status.
      Parameters:
      status -
      Returns:
    • withDetail

      public Problem withDetail(@Nullable String detail)
      Create a new Problem by copying its attributes and replacing the detail.
      Parameters:
      detail -
      Returns:
    • withInstance

      public Problem withInstance(@Nullable URI instance)
      Create a new Problem by copying its attributes and replacing the instance.
      Parameters:
      instance -
      Returns:
    • withProperties

      public <T> Problem.ExtendedProblem<T> withProperties(T payload)
      Creates a new Problem.ExtendedProblem with the given payload as additional properties.
      Type Parameters:
      T -
      Parameters:
      payload - must not be null.
      Returns:
    • withProperties

      public Problem.ExtendedProblem<Map<String,Object>> withProperties(Consumer<Map<String,Object>> consumer)
      Returns an Problem.ExtendedProblem with a Map<String,Object> populated by the given consumer as payload.
      Parameters:
      consumer - must not be null.
      Returns:
    • withProperties

      public Problem.ExtendedProblem<Map<String,Object>> withProperties(Map<String,Object> properties)
      Returns an Problem.ExtendedProblem with the given Map unwrapping as additional properties.
      Parameters:
      properties - must not be null.
      Returns:
    • getType

      public @Nullable URI getType()
    • getTitle

      public @Nullable String getTitle()
    • getStatus

      public @Nullable org.springframework.http.HttpStatus getStatus()
    • getDetail

      public @Nullable String getDetail()
    • getInstance

      public @Nullable URI getInstance()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object