List of usage examples for org.springframework.core.convert ConverterNotFoundException ConverterNotFoundException
public ConverterNotFoundException(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType)
From source file:org.focusns.common.web.widget.mvc.method.WidgetMethodArgumentResolver.java
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { ///*w w w. j a va2 s.c om*/ Object value = null; if (parameter.hasParameterAnnotation(WidgetAttribute.class)) { value = getWidgetAttributeValue(parameter, webRequest); } else if (parameter.hasParameterAnnotation(WidgetPref.class)) { value = getWidgetPrefValue(parameter, webRequest); } // if (value != null) { ConversionService conversionService = (ConversionService) webRequest .getAttribute(ConversionService.class.getName(), WebRequest.SCOPE_REQUEST); if (conversionService.canConvert(value.getClass(), parameter.getParameterType())) { value = conversionService.convert(value, parameter.getParameterType()); } else { throw new ConverterNotFoundException(TypeDescriptor.forObject(value), TypeDescriptor.valueOf(parameter.getParameterType())); } } // return value; }
From source file:com._4dconcept.springframework.data.marklogic.core.convert.MappingMarklogicConverter.java
@Override public <R> R read(Class<R> returnType, MarklogicContentHolder holder) { ResultItem resultItem = (ResultItem) holder.getContent(); if (String.class.equals(returnType)) { return returnType.cast(resultItem.asString()); }/* w ww. j a v a 2 s . co m*/ R result = null; if (returnType.isPrimitive()) { try { Method method = MarklogicTypeUtils.primitiveMap.get(returnType).getMethod("valueOf", String.class); @SuppressWarnings("unchecked") R obj = (R) method.invoke(null, resultItem.asString()); result = obj; } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { LOGGER.debug("Unable to generate primitive value for type " + returnType.getName()); } } if (result != null) { return result; } ConversionService conversionService = getConversionService(); if (conversionService.canConvert(resultItem.getClass(), returnType)) { R convert = conversionService.convert(resultItem, returnType); if (convert == null) { throw new ConversionFailedException(TypeDescriptor.forObject(resultItem), TypeDescriptor.valueOf(returnType), resultItem, new NullPointerException()); } return convert; } else { throw new ConverterNotFoundException(TypeDescriptor.forObject(resultItem), TypeDescriptor.valueOf(returnType)); } }
From source file:com._4dconcept.springframework.data.marklogic.core.convert.MappingMarklogicConverter.java
@Override public void write(Object source, MarklogicContentHolder holder) { TypeDescriptor sourceDescriptor = TypeDescriptor.forObject(source); TypeDescriptor targetDescriptor = TypeDescriptor.valueOf(String.class); if (getConversionService().canConvert(sourceDescriptor, targetDescriptor)) { String content = getConversionService().convert(source, String.class); if (content == null) { throw new ConversionFailedException(sourceDescriptor, targetDescriptor, source, new NullPointerException("Conversion result is not e")); } else {/*from ww w . j a v a2 s. co m*/ holder.setContent(content); } } else { throw new ConverterNotFoundException(sourceDescriptor, targetDescriptor); } }
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 av a 2 s .c om "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; }