List of usage examples for org.springframework.core.convert.support GenericConversionService addConverter
@Override public void addConverter(GenericConverter converter)
From source file:playground.Application.java
@Bean ConversionService conversionService() {/*from w w w .j a v a2 s. c o m*/ GenericConversionService service = new GenericConversionService(); service.addConverter(new ReactiveStreamsToCompletableFutureConverter()); service.addConverter(new ReactiveStreamsToRxJava1Converter()); return service; }
From source file:org.ldaptive.beans.spring.SpringLdapEntryMapper.java
/** * Adds default converters to the supplied conversion service. * * @param service to add default converters to *///from w w w. j a v a2 s . com protected void addDefaultConverters(final GenericConversionService service) { if (!service.canConvert(String.class, Calendar.class)) { service.addConverter(new Converter<String, Calendar>() { @Override public Calendar convert(final String s) { final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder(); return transcoder.decodeStringValue(s); } }); } if (!service.canConvert(Calendar.class, String.class)) { service.addConverter(new Converter<Calendar, String>() { @Override public String convert(final Calendar c) { final GeneralizedTimeValueTranscoder transcoder = new GeneralizedTimeValueTranscoder(); return transcoder.encodeStringValue(c); } }); } }
From source file:net.cpollet.jixture.fixtures.transformers.TestFileFixtureTransformer.java
@Before public void setUp() throws NoSuchFieldException { GenericConversionService genericConversionService = new GenericConversionService(); genericConversionService.addConverter(new Converter<String, Integer>() { @Override//from www.ja va2 s . c om public Integer convert(String source) { if (0 == source.length()) { return null; } return NumberUtils.parseNumber(source, Integer.class); } }); Mockito.when(conversionServiceFactoryBean.getObject()).thenReturn(genericConversionService); mockCartEntry(); mockProduct(); }
From source file:org.fenixedu.bennu.spring.BennuSpringConfiguration.java
@Bean public ConversionService conversionService(GenericConversionService service) { service.addConverter(new DomainObjectConverter()); service.addConverter(new LocalizedStringConverter()); service.addConverter(new UserFromUsernameConverter()); return service; }
From source file:org.zhangmz.cymbidium.authority.conf.WebMvcConfig.java
/** * //from ww w. java 2 s .c o m */ @PostConstruct public void initEditableValidation() { ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter .getWebBindingInitializer(); if (initializer.getConversionService() != null) { GenericConversionService genericConversionService = (GenericConversionService) initializer .getConversionService(); genericConversionService.addConverter(new StringToDateConverter()); } }
From source file:org.ldaptive.beans.spring.SpringLdapEntryMapper.java
/** * Creates an evaluation context to use in the spring class descriptor. Adds * the default converters from the default conversion service. * * @param object to supply to the evaluation context * * @return evalutation context/*w w w.ja va 2 s .c om*/ */ protected EvaluationContext createEvaluationContext(final Object object) { final GenericConversionService conversionService = new GenericConversionService(); DefaultConversionService.addDefaultConverters(conversionService); if (converters != null) { for (Converter<?, ?> converter : converters) { conversionService.addConverter(converter); } } addDefaultConverters(conversionService); final StandardEvaluationContext context = new StandardEvaluationContext(object); context.setTypeConverter(new StandardTypeConverter(conversionService)); return context; }
From source file:org.fenixedu.bennu.spring.FenixEDUBaseController.java
@InitBinder public void initBinder(final WebDataBinder binder) { GenericConversionService conversionService = (GenericConversionService) binder.getConversionService(); if (!conversionService.canConvert(String.class, IBean.class)) { GsonBuilder builder = new GsonBuilder(); registerTypeAdapters(builder);/* w w w .j a va2s. c om*/ conversionService.addConverter(new BeanConverterService(builder)); } conversionService.addConverter(new CountryConverterService()); conversionService.addConverter(new DistrictConverterService()); conversionService.addConverter(new MunicipalityConverterService()); }
From source file:com.frank.search.solr.core.convert.CustomConversions.java
/** * Register custom converters within given {@link org.springframework.core.convert.support.GenericConversionService} * * @param conversionService must not be null *//*w ww . j a v a2s. c o m*/ public void registerConvertersIn(GenericConversionService conversionService) { Assert.notNull(conversionService); for (Object converter : converters) { if (converter instanceof Converter) { conversionService.addConverter((Converter<?, ?>) converter); } else if (converter instanceof ConverterFactory) { conversionService.addConverterFactory((ConverterFactory<?, ?>) converter); } else if (converter instanceof GenericConverter) { conversionService.addConverter((GenericConverter) converter); } else { throw new IllegalArgumentException("Given object '" + converter + "' expected to be a Converter, ConverterFactory or GenericeConverter!"); } } }
From source file:tv.arte.resteventapi.core.querying.convertion.RestEventApiCustomConvertersLoader.java
/** * Initializes the RestEventApi custom converters at the end of the Spring context loading *//* ww w . j a v a 2 s .c om*/ @SuppressWarnings("rawtypes") public void onApplicationEvent(ContextRefreshedEvent event) { if (conversionService instanceof GenericConversionService) { GenericConversionService genericConversionService = (GenericConversionService) conversionService; Map<String, Object> converters = event.getApplicationContext() .getBeansWithAnnotation(RestEventApiConverter.class); for (Entry<String, Object> beanEntry : converters.entrySet()) { Object beanEntryValue = beanEntry.getValue(); if (beanEntryValue instanceof Converter) { genericConversionService.addConverter((Converter) beanEntryValue); if (logger.isDebugEnabled()) logger.debug("Converter bean with name " + beanEntry.getKey() + " has been added"); } else if (beanEntryValue instanceof GenericConverter) { genericConversionService.addConverter((GenericConverter) beanEntryValue); if (logger.isDebugEnabled()) logger.debug("Converter bean with name " + beanEntry.getKey() + " has been added"); } else { logger.error( "Cannot consider the bean with name " + beanEntry.getKey() + " as a valid converter."); } } } else { String errorMessage = "RestEventApi custom convertes failed to be initialized. The convertion service is not of the expected type."; logger.error(errorMessage); throw new RestEventApiRuntimeException(errorMessage); } }
From source file:io.twipple.springframework.data.clusterpoint.convert.support.CustomConversions.java
/** * Populates the given {@link GenericConversionService} with the convertes registered. * * @param conversionService the service to register. *///from w w w. j av a2s.c o m public void registerConvertersIn(@NotNull GenericConversionService conversionService) { Assert.notNull(conversionService); for (Object converter : converters) { boolean added = false; if (converter instanceof Converter) { conversionService.addConverter((Converter<?, ?>) converter); added = true; } if (converter instanceof ConverterFactory) { conversionService.addConverterFactory((ConverterFactory<?, ?>) converter); added = true; } if (converter instanceof GenericConverter) { conversionService.addConverter((GenericConverter) converter); added = true; } if (!added) { throw new IllegalArgumentException( "Given set contains element that is neither Converter nor ConverterFactory!"); } } }