Package org.springframework.core.convert

Examples of org.springframework.core.convert.ConversionService


    PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);

    ConversionFailedException firstAttemptEx = null;

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null && typeDescriptor != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(newValue);
      TypeDescriptor targetTypeDesc = typeDescriptor;
      if (conversionService.canConvert(sourceTypeDesc, targetTypeDesc)) {
        try {
          return (T) conversionService.convert(convertedValue, sourceTypeDesc, targetTypeDesc);
        }
        catch (ConversionFailedException ex) {
          // fallback to default conversion logic below
          firstAttemptEx = ex;
        }
View Full Code Here


    converterRegistry.addConverter(new PropertiesToStringConverter());
    converterRegistry.addConverter(new StringToPropertiesConverter());
  }

  private static void addCollectionConverters(ConverterRegistry converterRegistry) {
    ConversionService conversionService = (ConversionService) converterRegistry;   
    converterRegistry.addConverter(new ArrayToCollectionConverter(conversionService));
    converterRegistry.addConverter(new CollectionToArrayConverter(conversionService));

    converterRegistry.addConverter(new ArrayToArrayConverter(conversionService));
    converterRegistry.addConverter(new CollectionToCollectionConverter(conversionService));
View Full Code Here

    converterRegistry.addConverter(new CollectionToObjectConverter(conversionService));
    converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService));
  }
 
  private static void addFallbackConverters(ConverterRegistry converterRegistry) {
    ConversionService conversionService = (ConversionService) converterRegistry;
    converterRegistry.addConverter(new ObjectToObjectConverter());
    converterRegistry.addConverter(new IdToEntityConverter(conversionService));
    converterRegistry.addConverter(new FallbackObjectToStringConverter());   
  }
View Full Code Here

    // Custom editor for this type?
    PropertyEditor editor = this.propertyEditorRegistry.findCustomEditor(requiredType, propertyName);

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(convertedValue);
      if (conversionService.canConvert(sourceTypeDesc, typeDescriptor)) {
        return (T) conversionService.convert(convertedValue, sourceTypeDesc, typeDescriptor);
      }
    }

    // Value not of required type?
    if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
View Full Code Here

  @Override
  public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    if (converter == null && beanFactory instanceof ConfigurableBeanFactory) {
      ConfigurableBeanFactory cFB = (ConfigurableBeanFactory) beanFactory;
      ConversionService conversionService = cFB.getConversionService();

      converter = (conversionService != null ? new Converter(conversionService) : new Converter(
          cFB.getTypeConverter()));
    }
  }
View Full Code Here

          if (results.size() == 1) {
            // A List of size 1 get's returned as the object at list[0].
            Object obj = results.get(0);
            if (obj.getClass() != targetType) {
              // I can't just return it as-is, I have to convert it first.
              ConversionService conv = getConversionService();
              if (conv.canConvert(obj.getClass(), targetType)) {
                return conv.convert(obj, targetType);
              } else {
                throw new DataAccessResourceFailureException(
                    "Can't find a converter to to convert " + obj
                        .getClass() + " returned from M/R job to required type " + targetType);
              }
View Full Code Here

    public void doRuntimeConfiguration(RuntimeSpringConfiguration springConfig) {
        ApplicationContext context = springConfig.getUnrefreshedApplicationContext();
        AutowireCapableBeanFactory autowireCapableBeanFactory = context.getAutowireCapableBeanFactory();
        if(autowireCapableBeanFactory instanceof ConfigurableListableBeanFactory) {
            ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory)autowireCapableBeanFactory;
            ConversionService existingConversionService = beanFactory.getConversionService();
            ConverterRegistry converterRegistry;
            if(existingConversionService == null) {
                GenericConversionService conversionService = new GenericConversionService();
                converterRegistry = conversionService;
                beanFactory.setConversionService(conversionService);
View Full Code Here

public class TestBeanWrapper {

  @Test
  public void testBeanWrapper() {
    BeanWrapper memberWrapped = new BeanWrapperImpl(new Member());
    ConversionService conversionService = new DefaultFormattingConversionService();
    memberWrapped.setConversionService(conversionService );
    memberWrapped.setAutoGrowNestedPaths(true);
    PropertyValue pv1 = new PropertyValue("first", "john");
    PropertyValue pv2 = new PropertyValue("last", "doe");
   
View Full Code Here

                                                     String attributeName,
                                                     MethodParameter parameter,
                                                     WebDataBinderFactory binderFactory,
                                                     NativeWebRequest request) throws Exception {
        DataBinder binder = binderFactory.createBinder(request, null, attributeName);
        ConversionService conversionService = binder.getConversionService();
        if (conversionService != null) {
            TypeDescriptor source = TypeDescriptor.valueOf(String.class);
            TypeDescriptor target = new TypeDescriptor(parameter);
            if (conversionService.canConvert(source, target)) {
                return binder.convertIfNecessary(sourceValue, parameter.getParameterType(), parameter);
            }
        }
        return null;
    }
View Full Code Here

        Set<Object> converters = new HashSet<Object>();
        converters.add(new RopRequestMessageConverter());
        serviceFactoryBean.setConverters(converters);

        serviceFactoryBean.afterPropertiesSet();
        ConversionService conversionService = serviceFactoryBean.getObject();
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setParameter("userName", "tom");
        request.setParameter("address",
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                        "<address zoneCode=\"1\" doorCode=\"002\">\n" +
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.ConversionService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.