Package org.springframework.core.convert.converter

Examples of org.springframework.core.convert.converter.ConverterRegistry


        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);
            }
            else {
                converterRegistry = (ConverterRegistry)existingConversionService;
            }

            converterRegistry.addConverter(new Converter<GrailsApplication, org.codehaus.groovy.grails.commons.GrailsApplication>() {
                @Override
                public org.codehaus.groovy.grails.commons.GrailsApplication convert(GrailsApplication source) {
                    return new LegacyGrailsApplication(source);
                }
            });
            converterRegistry.addConverter(new Converter<ConfigMap.NullSafeNavigator, Object>() {
                @Override
                public Object convert(ConfigMap.NullSafeNavigator source) {
                    return null;
                }
            });
View Full Code Here


    assertEquals(new Integer("3"), result.get(2));
  }

  @Test
  public void testSpr7766() throws Exception {
    ConverterRegistry registry = (conversionService);
    registry.addConverter(new ColorConverter());
    List<Color> colors = (List<Color>) conversionService.convert(new String[] { "ffffff", "#000000" }, TypeDescriptor.valueOf(String[].class), new TypeDescriptor(new MethodParameter(getClass().getMethod("handlerMethod", List.class), 0)));
    assertEquals(2, colors.size());
    assertEquals(Color.WHITE, colors.get(0));
    assertEquals(Color.BLACK, colors.get(1));
  }
View Full Code Here

            return new TestGraphDatabaseFactory().newImpermanentDatabase();
        }

        @Override
        protected ConversionService neo4jConversionService() throws Exception {
            ConverterRegistry converterRegistry = (ConverterRegistry) super.neo4jConversionService();

            converterRegistry.addConverter(new Converter<CustomType, String>() {
                @Override
                public String convert(CustomType source) {
                    return source.value + " encoded using string";
                }
            });
            converterRegistry.addConverter(new Converter<String, CustomType>() {
                @Override
                public CustomType convert(String source) {
                    return new CustomType(source + " decoded using string");
                }
            });

            converterRegistry.addConverter(new Converter<CustomType, byte[]>() {
                @Override
                public byte[] convert(CustomType source) {
                    return (source.value + " encoded using byte array").getBytes();
                }
            });
            converterRegistry.addConverter(new Converter<byte[], CustomType>() {
                @Override
                public CustomType convert(byte[] source) {
                    return new CustomType(new String(source) + " decoded using byte array");
                }
            });
View Full Code Here

        return conversionService;
    }

    public void addConverters(ConversionService service) {
        if (service instanceof ConverterRegistry) {
            ConverterRegistry registry = (ConverterRegistry) service;
            registry.addConverter(new DateToStringConverter());
            registry.addConverter(new DateToLongConverter());
            registry.addConverter(new StringToDateConverter());
            registry.addConverter(new NumberToDateConverter());
            registry.addConverter(new EnumToStringConverter());
            registry.addConverter(new EnumToIntegerConverter());
            registry.addConverter(new ShapeToStringConverter());
            registry.addConverter(new StringToShapeConverter());
            registry.addConverter(new PointToStringConverter());
            registry.addConverter(new StringToPointConverter());
            registry.addConverterFactory(new StringToEnumConverterFactory());
            registry.addConverterFactory(new NumberToEnumConverterFactory());
        } else {
            throw new IllegalArgumentException("conversionservice is no ConverterRegistry:" + service);
        }
    }
View Full Code Here

  @SuppressWarnings("rawtypes")
  public ConversionService getObject() {
    ConversionService conversionService = super.getObject();
    if (conversionService instanceof ConverterRegistry) {
      ConverterRegistry registry = (ConverterRegistry) conversionService;
      if (cachedConverters == null) {
        cachedConverters = BeanUtils.getBeansOfType(Converter.class);
        ConversionServiceFactory.registerConverters(new LinkedHashSet<Converter>(cachedConverters.values()),
            registry);
      }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.converter.ConverterRegistry

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.