Package org.springframework.beans
Class 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 Description static String
ERROR_CODE
Error code that a type mismatch error will be registered with.
Constructor Summary
Constructors Constructor Description TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType)
Create a newTypeMismatchException
.TypeMismatchException(PropertyChangeEvent propertyChangeEvent, Class<?> requiredType, Throwable cause)
Create a newTypeMismatchException
.TypeMismatchException(Object value, Class<?> requiredType)
Create a newTypeMismatchException
without aPropertyChangeEvent
.TypeMismatchException(Object value, Class<?> requiredType, Throwable cause)
Create a newTypeMismatchException
without aPropertyChangeEvent
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 benull
).void
initPropertyName(String propertyName)
Initialize this exception's property name for exposure throughgetPropertyName()
, as an alternative to having it initialized via aPropertyChangeEvent
.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
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 newTypeMismatchException
.- Parameters:
propertyChangeEvent
- the PropertyChangeEvent that resulted in the problemrequiredType
- the required target type
TypeMismatchException
public TypeMismatchException(PropertyChangeEvent propertyChangeEvent, @Nullable Class<?> requiredType, @Nullable Throwable cause)
Create a newTypeMismatchException
.- Parameters:
propertyChangeEvent
- the PropertyChangeEvent that resulted in the problemrequiredType
- the required target type (ornull
if not known)cause
- the root cause (may benull
)
TypeMismatchException
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType)
Create a newTypeMismatchException
without aPropertyChangeEvent
.- Parameters:
value
- the offending value that couldn't be converted (may benull
)requiredType
- the required target type (ornull
if not known)- See Also:
initPropertyName(java.lang.String)
TypeMismatchException
public TypeMismatchException(@Nullable Object value, @Nullable Class<?> requiredType, @Nullable Throwable cause)
Create a newTypeMismatchException
without aPropertyChangeEvent
.- Parameters:
value
- the offending value that couldn't be converted (may benull
)requiredType
- the required target type (ornull
if not known)cause
- the root cause (may benull
)- See Also:
initPropertyName(java.lang.String)
Method Detail
initPropertyName
public void initPropertyName(String propertyName)
Initialize this exception's property name for exposure throughgetPropertyName()
, as an alternative to having it initialized via aPropertyChangeEvent
.- 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 classPropertyAccessException
getValue
@Nullable public Object getValue()
Return the offending value (may benull
).- Overrides:
getValue
in classPropertyAccessException
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 classPropertyAccessException