catch ConversionException and ConvertedNotFoundException in BeanWrapper's convertIfNecessary as well, in order to support constructor resolution (SPR-6563)
This commit is contained in:
parent
2153b2fbd5
commit
1c33206042
|
@ -42,6 +42,7 @@ import org.springframework.core.CollectionFactory;
|
|||
import org.springframework.core.GenericCollectionTypeResolver;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.convert.ConversionException;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
@ -417,12 +418,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
try {
|
||||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConverterNotFoundException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
throw new ConversionNotSupportedException(value, requiredType, ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1105,12 +1112,12 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
throw new MethodInvocationException(propertyChangeEvent, ex.getTargetException());
|
||||
}
|
||||
}
|
||||
catch (ConversionException ex) {
|
||||
catch (ConverterNotFoundException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
|
||||
throw new TypeMismatchException(pce, pd.getPropertyType(), ex);
|
||||
throw new ConversionNotSupportedException(pce, pd.getPropertyType(), ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
catch (ConversionException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
|
||||
throw new TypeMismatchException(pce, pd.getPropertyType(), ex);
|
||||
|
@ -1120,6 +1127,11 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
|||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
|
||||
throw new ConversionNotSupportedException(pce, pd.getPropertyType(), ex);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
|
||||
throw new TypeMismatchException(pce, pd.getPropertyType(), ex);
|
||||
}
|
||||
catch (IllegalAccessException ex) {
|
||||
PropertyChangeEvent pce =
|
||||
new PropertyChangeEvent(this.rootObject, this.nestedPath + propertyName, oldValue, pv.getValue());
|
||||
|
|
|
@ -19,26 +19,32 @@ package org.springframework.beans;
|
|||
import java.beans.PropertyChangeEvent;
|
||||
|
||||
/**
|
||||
* Exception thrown when no suitable editor can be found to set a bean property.
|
||||
* Exception thrown when no suitable editor or converter can be found for a bean property.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ConversionNotSupportedException extends TypeMismatchException {
|
||||
|
||||
public ConversionNotSupportedException(PropertyChangeEvent propertyChangeEvent, Class requiredType) {
|
||||
super(propertyChangeEvent, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ConversionNotSupportedException.
|
||||
* @param propertyChangeEvent the PropertyChangeEvent that resulted in the problem
|
||||
* @param requiredType the required target type (or <code>null</code> if not known)
|
||||
* @param cause the root cause (may be <code>null</code>)
|
||||
*/
|
||||
public ConversionNotSupportedException(PropertyChangeEvent propertyChangeEvent, Class requiredType, Throwable cause) {
|
||||
super(propertyChangeEvent, requiredType, cause);
|
||||
}
|
||||
|
||||
public ConversionNotSupportedException(Object value, Class requiredType) {
|
||||
super(value, requiredType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ConversionNotSupportedException.
|
||||
* @param value the offending value that couldn't be converted (may be <code>null</code>)
|
||||
* @param requiredType the required target type (or <code>null</code> if not known)
|
||||
* @param cause the root cause (may be <code>null</code>)
|
||||
*/
|
||||
public ConversionNotSupportedException(Object value, Class requiredType, Throwable cause) {
|
||||
super(value, requiredType, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public class TestClient {
|
|||
|
||||
private boolean bool;
|
||||
|
||||
private List<String> stringList;
|
||||
|
||||
private Resource[] resourceArray;
|
||||
|
||||
private List<Resource> resourceList;
|
||||
|
@ -56,6 +58,14 @@ public class TestClient {
|
|||
this.bool = bool;
|
||||
}
|
||||
|
||||
public List<String> getStringList() {
|
||||
return stringList;
|
||||
}
|
||||
|
||||
public void setStringList(List<String> stringList) {
|
||||
this.stringList = stringList;
|
||||
}
|
||||
|
||||
public Resource[] getResourceArray() {
|
||||
return resourceArray;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,14 @@
|
|||
|
||||
<bean id="testClient" class="org.springframework.context.conversionservice.TestClient">
|
||||
<property name="bool" value="true"/>
|
||||
<property name="stringList">
|
||||
<list>
|
||||
<value>#{'test-' + strValue + '-end'}</value>
|
||||
<value>#{'test-' + strValue}</value>
|
||||
<value>#{'test-' + numValue+ '-end'}</value>
|
||||
<value>#{'test-' + numValue}</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="resourceArray">
|
||||
<value>classpath:test.xml</value>
|
||||
</property>
|
||||
|
@ -36,7 +44,15 @@
|
|||
<bean class="org.springframework.context.conversionservice.Bar">
|
||||
<constructor-arg value ="value2" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="numValue" class="java.lang.Integer">
|
||||
<constructor-arg value="111"/>
|
||||
</bean>
|
||||
|
||||
<bean id="strValue" class="java.lang.String">
|
||||
<constructor-arg value="222"/>
|
||||
</bean>
|
||||
|
||||
<context:annotation-config />
|
||||
|
||||
</beans>
|
||||
|
|
Loading…
Reference in New Issue