Class ObjectError

All Implemented Interfaces:
Serializable, MessageSourceResolvable
Direct Known Subclasses:
FieldError

public class ObjectError extends DefaultMessageSourceResolvable
Encapsulates an object error, that is, a global reason for rejecting an object.

See the DefaultMessageCodesResolver javadoc for details on how a message code list is built for an ObjectError.

Since:
10.03.2003
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • ObjectError

      public ObjectError(String objectName, @Nullable String defaultMessage)
      Create a new instance of the ObjectError class.
      Parameters:
      objectName - the name of the affected object
      defaultMessage - the default message to be used to resolve this message
    • ObjectError

      public ObjectError(String objectName, @Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage)
      Create a new instance of the ObjectError class.
      Parameters:
      objectName - the name of the affected object
      codes - the codes to be used to resolve this message
      arguments - the array of arguments to be used to resolve this message
      defaultMessage - the default message to be used to resolve this message
  • Method Details

    • getObjectName

      public String getObjectName()
      Return the name of the affected object.
    • wrap

      public void wrap(Object source)
      Preserve the source behind this error: possibly an Exception (typically PropertyAccessException) or a Bean Validation ConstraintViolation.

      Note that any such source object is being stored as transient: that is, it won't be part of a serialized error representation.

      Parameters:
      source - the source object
      Since:
      5.0.4
    • unwrap

      public <T> T unwrap(Class<T> sourceType)
      Unwrap the source behind this error: possibly an Exception (typically PropertyAccessException) or a Bean Validation ConstraintViolation.

      The cause of the outermost exception will be introspected as well, e.g. the underlying conversion exception or exception thrown from a setter (instead of having to unwrap the PropertyAccessException in turn).

      Returns:
      the source object of the given type
      Throws:
      IllegalArgumentException - if no such source object is available (i.e. none specified or not available anymore after deserialization)
      Since:
      5.0.4
    • contains

      public boolean contains(Class<?> sourceType)
      Check the source behind this error: possibly an Exception (typically PropertyAccessException) or a Bean Validation ConstraintViolation.

      The cause of the outermost exception will be introspected as well, e.g. the underlying conversion exception or exception thrown from a setter (instead of having to unwrap the PropertyAccessException in turn).

      Returns:
      whether this error has been caused by a source object of the given type
      Since:
      5.0.4
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class DefaultMessageSourceResolvable
    • hashCode

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

      public String toString()
      Description copied from class: DefaultMessageSourceResolvable
      The default implementation exposes the attributes of this MessageSourceResolvable.

      To be overridden in more specific subclasses, potentially including the resolvable content through resolvableToString().

      Overrides:
      toString in class DefaultMessageSourceResolvable
      See Also: