forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added Field context variant to TypeConverter interface in beans module;
@value injection works in combination with formatting rules such as @DateTimeFormat Issue: SPR-9637
- Loading branch information
Showing
11 changed files
with
195 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2002-2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.beans; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import org.springframework.core.MethodParameter; | ||
import org.springframework.core.convert.ConversionException; | ||
import org.springframework.core.convert.ConverterNotFoundException; | ||
|
||
/** | ||
* Base implementation of the {@link TypeConverter} interface, using a package-private delegate. | ||
* Mainly serves as base class for {@link BeanWrapperImpl}. | ||
* | ||
* @author Juergen Hoeller | ||
* @since 3.2 | ||
* @see SimpleTypeConverter | ||
*/ | ||
public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport implements TypeConverter { | ||
|
||
TypeConverterDelegate typeConverterDelegate; | ||
|
||
|
||
public <T> T convertIfNecessary(Object value, Class<T> requiredType) throws TypeMismatchException { | ||
return doConvert(value, requiredType, null, null); | ||
} | ||
|
||
public <T> T convertIfNecessary(Object value, Class<T> requiredType, MethodParameter methodParam) | ||
throws TypeMismatchException { | ||
|
||
return doConvert(value, requiredType, methodParam, null); | ||
} | ||
|
||
public <T> T convertIfNecessary(Object value, Class<T> requiredType, Field field) | ||
throws TypeMismatchException { | ||
|
||
return doConvert(value, requiredType, null, field); | ||
} | ||
|
||
private <T> T doConvert(Object value, Class<T> requiredType, MethodParameter methodParam, Field field) | ||
throws TypeMismatchException { | ||
try { | ||
if (field != null) { | ||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, field); | ||
} | ||
else { | ||
return this.typeConverterDelegate.convertIfNecessary(value, requiredType, methodParam); | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.