org.springframework.beans

## Class TypeMismatchException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - org.springframework.core.NestedRuntimeException
        - - org.springframework.beans.BeansException
          - - org.springframework.beans.PropertyAccessException
            - - org.springframework.beans.TypeMismatchException

- All Implemented Interfaces:
    Serializable
  Direct Known Subclasses:
    ConversionNotSupportedException, MethodArgumentTypeMismatchException

      public class TypeMismatchException
      extends PropertyAccessException

  Exception thrown on a type mismatch when trying to set a bean property.
  Author:
    Rod Johnson, Juergen Hoeller
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ERROR_CODE` Error code that a type mismatch error will be registered with.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TypeMismatchException(Object value, Class<?> requiredType)` Create a new `TypeMismatchException` without a `PropertyChangeEvent`.
    `TypeMismatchException(Object value, Class<?> requiredType, Throwable cause)` Create a new `TypeMismatchException` without a `PropertyChangeEvent`.
    `TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType)` Create a new `TypeMismatchException`.
    `TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType, Throwable cause)` Create a new `TypeMismatchException`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getErrorCode()` Return a corresponding error code for this type of exception.
    `String` | `getPropertyName()` Return the name of the affected property, if available.
    `Class<?>` | `getRequiredType()` Return the required target type, if any.
    `Object` | `getValue()` Return the offending value (may be `null`).
    `void` | `initPropertyName(String propertyName)` Initialize this exception's property name for exposure through `getPropertyName()`, as an alternative to having it initialized via a `PropertyChangeEvent`.

    - ### Methods inherited from class org.springframework.beans.PropertyAccessException

      `getPropertyChangeEvent`

    - ### Methods inherited from class org.springframework.core.NestedRuntimeException

      `contains, getMessage, getMostSpecificCause, getRootCause`

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### ERROR_CODE

          public static final String ERROR_CODE

      Error code that a type mismatch error will be registered with.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TypeMismatchException

          public TypeMismatchException(PropertyChangeEvent propertyChangeEvent,
                                       Class<?> requiredType)

      Create a new `TypeMismatchException`.
      Parameters:
        `propertyChangeEvent` - the PropertyChangeEvent that resulted in the problem
        `requiredType` - the required target type

    - #### TypeMismatchException

          public TypeMismatchException(PropertyChangeEvent propertyChangeEvent,
                                       @Nullable
                                       Class<?> requiredType,
                                       @Nullable
                                       Throwable cause)

      Create a new `TypeMismatchException`.
      Parameters:
        `propertyChangeEvent` - the PropertyChangeEvent that resulted in the problem
        `requiredType` - the required target type (or `null` if not known)
        `cause` - the root cause (may be `null`)

    - #### TypeMismatchException

          public TypeMismatchException(@Nullable
                                       Object value,
                                       @Nullable
                                       Class<?> requiredType)

      Create a new `TypeMismatchException` without a `PropertyChangeEvent`.
      Parameters:
        `value` - the offending value that couldn't be converted (may be `null`)
        `requiredType` - the required target type (or `null` if not known)
      See Also:
        `initPropertyName(java.lang.String)`

    - #### TypeMismatchException

          public TypeMismatchException(@Nullable
                                       Object value,
                                       @Nullable
                                       Class<?> requiredType,
                                       @Nullable
                                       Throwable cause)

      Create a new `TypeMismatchException` without a `PropertyChangeEvent`.
      Parameters:
        `value` - the offending value that couldn't be converted (may be `null`)
        `requiredType` - the required target type (or `null` if not known)
        `cause` - the root cause (may be `null`)
      See Also:
        `initPropertyName(java.lang.String)`

  - ### Method Detail

    - #### initPropertyName

          public void initPropertyName(String propertyName)

      Initialize this exception's property name for exposure through `getPropertyName()`, as an alternative to having it initialized via a `PropertyChangeEvent`.
      Parameters:
        `propertyName` - the property name to expose
      Since:
        5.0.4
      See Also:
        `TypeMismatchException(Object, Class)`, `TypeMismatchException(Object, Class, Throwable)`

    - #### getPropertyName

          @Nullable
          public String getPropertyName()

      Return the name of the affected property, if available.
      Overrides:
        `getPropertyName` in class `PropertyAccessException`

    - #### getValue

          @Nullable
          public Object getValue()

      Return the offending value (may be `null`).
      Overrides:
        `getValue` in class `PropertyAccessException`

    - #### getRequiredType

          @Nullable
          public Class<?> getRequiredType()

      Return the required target type, if any.

    - #### getErrorCode

          public String getErrorCode()

      Description copied from class: `PropertyAccessException`
      Return a corresponding error code for this type of exception.
      Specified by:
        `getErrorCode` in class `PropertyAccessException`