Package org.springframework.core.convert

Examples of org.springframework.core.convert.ConversionService


  @SuppressWarnings({ "rawtypes", "unchecked" })
  private RepositoryInvoker getInvokerFor(Object repository, Class<?> expectedType) {

    Object proxy = getVerifyingProxy(repository, expectedType);
    Repositories repositories = new Repositories(context);
    ConversionService conversionService = new DefaultFormattingConversionService();

    return new CrudRepositoryInvoker((CrudRepository) proxy, repositories.getRepositoryInformationFor(Order.class),
        conversionService);
  }
View Full Code Here


    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

  protected Object createAttributeFromRequestValue(String sourceValue, 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

    StandardEvaluationContext context = new StandardEvaluationContext();
    context.addPropertyAccessor(new JspPropertyAccessor(pageContext));
    context.addPropertyAccessor(new MapAccessor());
    context.addPropertyAccessor(new EnvironmentAccessor());
    context.setBeanResolver(new BeanFactoryResolver(getRequestContext().getWebApplicationContext()));
    ConversionService conversionService = getConversionService(pageContext);
    if (conversionService != null) {
      context.setTypeConverter(new StandardTypeConverter(conversionService));
    }
    return context;
  }
View Full Code Here

        sec.addPropertyAccessor(new BeanFactoryAccessor());
        sec.addPropertyAccessor(new MapAccessor());
        sec.addPropertyAccessor(new EnvironmentAccessor());
        sec.setBeanResolver(new BeanFactoryResolver(evalContext.getBeanFactory()));
        sec.setTypeLocator(new StandardTypeLocator(evalContext.getBeanFactory().getBeanClassLoader()));
        ConversionService conversionService = evalContext.getBeanFactory().getConversionService();
        if (conversionService != null) {
          sec.setTypeConverter(new StandardTypeConverter(conversionService));
        }
        customizeEvaluationContext(sec);
        this.evaluationCache.put(evalContext, sec);
View Full Code Here

    }

    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    assertNotNull(initializer);

    ConversionService conversionService = initializer.getConversionService();
    assertNotNull(conversionService);
    assertTrue(conversionService instanceof FormattingConversionService);

    Validator validator = initializer.getValidator();
    assertNotNull(validator);
View Full Code Here

    assertEquals("id", dataBinder.getDisallowedFields()[0]);
  }

  @Test
  public void createBinderWithGlobalInitialization() throws Exception {
    ConversionService conversionService = new DefaultFormattingConversionService();
    bindingInitializer.setConversionService(conversionService);

    WebDataBinderFactory factory = createBinderFactory("initBinder", WebDataBinder.class);
    WebDataBinder dataBinder = factory.createBinder(webRequest, null, null);
View Full Code Here

    delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
    RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();

    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    ConversionService initializerConversionService = initializer.getConversionService();
    assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);

    verify(webMvcConfigurer).configureMessageConverters(converters.capture());
    verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
    verify(webMvcConfigurer).addFormatters(conversionService.capture());
View Full Code Here

    }
  }

  @Test
  public void testWithConversionService() {
    ConversionService conversionService = new DefaultConversionService();
    assertTrue(conversionService.canConvert(String.class, MediaType.class));
    MediaType mediaType = MediaType.parseMediaType("application/xml");
    assertEquals(mediaType, conversionService.convert("application/xml", MediaType.class));
  }
View Full Code Here

    converterRegistry.addConverter(new StringToUUIDConverter());
    converterRegistry.addConverter(UUID.class, String.class, new ObjectToStringConverter());
  }

  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));
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.