List of usage examples for org.springframework.core.convert.support ConversionUtils invokeConverter
@Nullable public static Object invokeConverter(GenericConverter converter, @Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType)
From source file:org.springframework.core.convert.support.GenericConversionService.java
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { assertNotNull(sourceType, targetType); if (logger.isDebugEnabled()) { logger.debug(//from w w w. j ava 2 s . c o m "Converting value " + StylerUtils.style(source) + " of " + sourceType + " to " + targetType); } if (sourceType == TypeDescriptor.NULL) { Assert.isTrue(source == null, "The value must be null if sourceType == TypeDescriptor.NULL"); Object result = convertNullSource(sourceType, targetType); if (logger.isDebugEnabled()) { logger.debug("Converted to " + StylerUtils.style(result)); } return result; } if (targetType == TypeDescriptor.NULL) { logger.debug("Converted to null"); return null; } Assert.isTrue(source == null || sourceType.getObjectType().isInstance(source)); GenericConverter converter = getConverter(sourceType, targetType); if (converter == null) { if (source == null || sourceType.isAssignableTo(targetType)) { logger.debug("No converter found - returning assignable source object as-is"); return source; } else { throw new ConverterNotFoundException(sourceType, targetType); } } Object result = ConversionUtils.invokeConverter(converter, source, sourceType, targetType); if (logger.isDebugEnabled()) { logger.debug("Converted to " + StylerUtils.style(result)); } return result; }