/** * Install the converters into the converter registry. * @param registry the converter registry */ @SuppressWarnings("deprecation") public static void registerConverters(ConverterRegistry registry) { DateFormatterRegistrar.addDateConverters(registry); registry.addConverter(new DateTimeToLocalDateConverter()); registry.addConverter(new DateTimeToLocalTimeConverter()); registry.addConverter(new DateTimeToLocalDateTimeConverter()); registry.addConverter(new DateTimeToDateMidnightConverter()); registry.addConverter(new DateTimeToMutableDateTimeConverter()); registry.addConverter(new DateTimeToInstantConverter()); registry.addConverter(new DateTimeToDateConverter()); registry.addConverter(new DateTimeToCalendarConverter()); registry.addConverter(new DateTimeToLongConverter()); registry.addConverter(new DateToReadableInstantConverter()); registry.addConverter(new CalendarToReadableInstantConverter()); registry.addConverter(new LongToReadableInstantConverter()); registry.addConverter(new LocalDateTimeToLocalDateConverter()); registry.addConverter(new LocalDateTimeToLocalTimeConverter()); }
/** * Install the converters into the converter registry. * @param registry the converter registry */ public static void registerConverters(ConverterRegistry registry) { DateFormatterRegistrar.addDateConverters(registry); registry.addConverter(new LocalDateTimeToLocalDateConverter()); registry.addConverter(new LocalDateTimeToLocalTimeConverter()); registry.addConverter(new ZonedDateTimeToLocalDateConverter()); registry.addConverter(new ZonedDateTimeToLocalTimeConverter()); registry.addConverter(new ZonedDateTimeToLocalDateTimeConverter()); registry.addConverter(new ZonedDateTimeToOffsetDateTimeConverter()); registry.addConverter(new ZonedDateTimeToInstantConverter()); registry.addConverter(new OffsetDateTimeToLocalDateConverter()); registry.addConverter(new OffsetDateTimeToLocalTimeConverter()); registry.addConverter(new OffsetDateTimeToLocalDateTimeConverter()); registry.addConverter(new OffsetDateTimeToZonedDateTimeConverter()); registry.addConverter(new OffsetDateTimeToInstantConverter()); registry.addConverter(new CalendarToZonedDateTimeConverter()); registry.addConverter(new CalendarToOffsetDateTimeConverter()); registry.addConverter(new CalendarToLocalDateConverter()); registry.addConverter(new CalendarToLocalTimeConverter()); registry.addConverter(new CalendarToLocalDateTimeConverter()); registry.addConverter(new CalendarToInstantConverter()); registry.addConverter(new LongToInstantConverter()); registry.addConverter(new InstantToLongConverter()); }
/** * Register the given Converter objects with the given target ConverterRegistry. * @param converters the converter objects: implementing {@link Converter}, * {@link ConverterFactory}, or {@link GenericConverter} * @param registry the target registry */ public static void registerConverters(Set<?> converters, ConverterRegistry registry) { if (converters != null) { for (Object converter : converters) { if (converter instanceof GenericConverter) { registry.addConverter((GenericConverter) converter); } else if (converter instanceof Converter<?, ?>) { registry.addConverter((Converter<?, ?>) converter); } else if (converter instanceof ConverterFactory<?, ?>) { registry.addConverterFactory((ConverterFactory<?, ?>) converter); } else { throw new IllegalArgumentException("Each converter object must implement one of the " + "Converter, ConverterFactory, or GenericConverter interfaces"); } } } }
/** * Add converters appropriate for most environments. * @param converterRegistry the registry of converters to add to (must also be castable to ConversionService, * e.g. being a {@link ConfigurableConversionService}) * @throws ClassCastException if the given ConverterRegistry could not be cast to a ConversionService */ public static void addDefaultConverters(ConverterRegistry converterRegistry) { addScalarConverters(converterRegistry); addCollectionConverters(converterRegistry); converterRegistry.addConverter(new ByteBufferConverter((ConversionService) converterRegistry)); if (jsr310Available) { Jsr310ConverterRegistrar.registerJsr310Converters(converterRegistry); } converterRegistry.addConverter(new ObjectToObjectConverter()); converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry)); converterRegistry.addConverter(new FallbackObjectToStringConverter()); if (javaUtilOptionalClassAvailable) { converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry)); } }
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)); converterRegistry.addConverter(new MapToMapConverter(conversionService)); converterRegistry.addConverter(new ArrayToStringConverter(conversionService)); converterRegistry.addConverter(new StringToArrayConverter(conversionService)); converterRegistry.addConverter(new ArrayToObjectConverter(conversionService)); converterRegistry.addConverter(new ObjectToArrayConverter(conversionService)); converterRegistry.addConverter(new CollectionToStringConverter(conversionService)); converterRegistry.addConverter(new StringToCollectionConverter(conversionService)); converterRegistry.addConverter(new CollectionToObjectConverter(conversionService)); converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService)); }
@PostConstruct public void init() { final ConfigurableApplicationContext ctx = applicationContextProvider().getConfigurableApplicationContext(); final DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(true); conversionService.setEmbeddedValueResolver(new CasConfigurationEmbeddedValueResolver(ctx)); ctx.getEnvironment().setConversionService(conversionService); final ConfigurableEnvironment env = (ConfigurableEnvironment) ctx.getParent().getEnvironment(); env.setConversionService(conversionService); final ConverterRegistry registry = (ConverterRegistry) DefaultConversionService.getSharedInstance(); registry.addConverter(zonedDateTimeToStringConverter()); }
/** * Add date converters to the specified registry. * @param converterRegistry the registry of converters to add to */ public static void addDateConverters(ConverterRegistry converterRegistry) { converterRegistry.addConverter(new DateToLongConverter()); converterRegistry.addConverter(new DateToCalendarConverter()); converterRegistry.addConverter(new CalendarToDateConverter()); converterRegistry.addConverter(new CalendarToLongConverter()); converterRegistry.addConverter(new LongToDateConverter()); converterRegistry.addConverter(new LongToCalendarConverter()); }
/** * Add all the default Search API converters to the given registry. * * @param registry The registry to add to. */ public static void addDefaultConverters(ConverterRegistry registry) { registry.addConverter(new DateToStringConverter()); registry.addConverter(new OffsetDateTimeToStringConverter()); registry.addConverter(new OffsetDateTimeToDateConverter()); registry.addConverter(new ZonedDateTimeToStringConverter()); registry.addConverter(new ZonedDateTimeToDateConverter()); registry.addConverter(new GeoPointToStringConverter()); }
/** * Add collection converters. * @param converterRegistry the registry of converters to add to (must also be castable to ConversionService, * e.g. being a {@link ConfigurableConversionService}) * @throws ClassCastException if the given ConverterRegistry could not be cast to a ConversionService * @since 4.2.3 */ public 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)); converterRegistry.addConverter(new MapToMapConverter(conversionService)); converterRegistry.addConverter(new ArrayToStringConverter(conversionService)); converterRegistry.addConverter(new StringToArrayConverter(conversionService)); converterRegistry.addConverter(new ArrayToObjectConverter(conversionService)); converterRegistry.addConverter(new ObjectToArrayConverter(conversionService)); converterRegistry.addConverter(new CollectionToStringConverter(conversionService)); converterRegistry.addConverter(new StringToCollectionConverter(conversionService)); converterRegistry.addConverter(new CollectionToObjectConverter(conversionService)); converterRegistry.addConverter(new ObjectToCollectionConverter(conversionService)); if (streamAvailable) { converterRegistry.addConverter(new StreamConverter(conversionService)); } }
private static void addScalarConverters(ConverterRegistry converterRegistry) { converterRegistry.addConverterFactory(new NumberToNumberConverterFactory()); converterRegistry.addConverterFactory(new StringToNumberConverterFactory()); converterRegistry.addConverter(Number.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCharacterConverter()); converterRegistry.addConverter(Character.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new NumberToCharacterConverter()); converterRegistry.addConverterFactory(new CharacterToNumberFactory()); converterRegistry.addConverter(new StringToBooleanConverter()); converterRegistry.addConverter(Boolean.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverterFactory(new StringToEnumConverterFactory()); converterRegistry.addConverter(Enum.class, String.class, new EnumToStringConverter((ConversionService) converterRegistry)); converterRegistry.addConverter(new StringToLocaleConverter()); converterRegistry.addConverter(Locale.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCharsetConverter()); converterRegistry.addConverter(Charset.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCurrencyConverter()); converterRegistry.addConverter(Currency.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToPropertiesConverter()); converterRegistry.addConverter(new PropertiesToStringConverter()); converterRegistry.addConverter(new StringToUUIDConverter()); converterRegistry.addConverter(UUID.class, String.class, new ObjectToStringConverter()); }
@Test public void testSpr7766() throws Exception { ConverterRegistry registry = (conversionService); registry.addConverter(new ColorConverter()); @SuppressWarnings("unchecked") 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)); }
protected void addConverters(ConverterRegistry registry) { if (configurers == null) return; for (FilesystemStoreConfigurer configurer : configurers) { configurer.configureFilesystemStoreConverters(registry); } }
private static void addScalarConverters(ConverterRegistry converterRegistry) { converterRegistry.addConverterFactory(new NumberToNumberConverterFactory()); converterRegistry.addConverterFactory(new StringToNumberConverterFactory()); converterRegistry.addConverter(Number.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCharacterConverter()); converterRegistry.addConverter(Character.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new NumberToCharacterConverter()); converterRegistry.addConverterFactory(new CharacterToNumberFactory()); converterRegistry.addConverter(new StringToBooleanConverter()); converterRegistry.addConverter(Boolean.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverterFactory(new StringToEnumConverterFactory()); converterRegistry.addConverter(new EnumToStringConverter((ConversionService) converterRegistry)); converterRegistry.addConverterFactory(new IntegerToEnumConverterFactory()); converterRegistry.addConverter(new EnumToIntegerConverter((ConversionService) converterRegistry)); converterRegistry.addConverter(new StringToLocaleConverter()); converterRegistry.addConverter(Locale.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCharsetConverter()); converterRegistry.addConverter(Charset.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToCurrencyConverter()); converterRegistry.addConverter(Currency.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new StringToPropertiesConverter()); converterRegistry.addConverter(new PropertiesToStringConverter()); converterRegistry.addConverter(new StringToUUIDConverter()); converterRegistry.addConverter(UUID.class, String.class, new ObjectToStringConverter()); }
/** * Install the converters into the converter registry. * @param registry the converter registry */ public static void registerConverters(ConverterRegistry registry) { DateFormatterRegistrar.addDateConverters(registry); registry.addConverter(new DateTimeToLocalDateConverter()); registry.addConverter(new DateTimeToLocalTimeConverter()); registry.addConverter(new DateTimeToLocalDateTimeConverter()); registry.addConverter(new DateTimeToDateMidnightConverter()); registry.addConverter(new DateTimeToMutableDateTimeConverter()); registry.addConverter(new DateTimeToInstantConverter()); registry.addConverter(new DateTimeToDateConverter()); registry.addConverter(new DateTimeToCalendarConverter()); registry.addConverter(new DateTimeToLongConverter()); registry.addConverter(new DateToReadableInstantConverter()); registry.addConverter(new CalendarToReadableInstantConverter()); }
private static void addScalarConverters(ConverterRegistry converterRegistry) { ConversionService conversionService = (ConversionService) converterRegistry; converterRegistry.addConverter(new StringToBooleanConverter()); converterRegistry.addConverter(Boolean.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverterFactory(new StringToNumberConverterFactory()); converterRegistry.addConverter(Number.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverterFactory(new NumberToNumberConverterFactory()); converterRegistry.addConverter(new StringToCharacterConverter()); converterRegistry.addConverter(Character.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new NumberToCharacterConverter()); converterRegistry.addConverterFactory(new CharacterToNumberFactory()); converterRegistry.addConverterFactory(new StringToEnumConverterFactory()); converterRegistry.addConverter(Enum.class, String.class, new EnumToStringConverter(conversionService)); converterRegistry.addConverter(new StringToLocaleConverter()); converterRegistry.addConverter(Locale.class, String.class, new ObjectToStringConverter()); converterRegistry.addConverter(new PropertiesToStringConverter()); converterRegistry.addConverter(new StringToPropertiesConverter()); converterRegistry.addConverter(new StringToUUIDConverter()); converterRegistry.addConverter(UUID.class, String.class, new ObjectToStringConverter()); }
@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)); }
@PostConstruct private void register() { if (conversionService instanceof ConverterRegistry) { ((ConverterRegistry) conversionService).addConverter(this); } else { throw new IllegalStateException("Can't register Converter to ConverterRegistry"); } }
public static void registerJsr310Converters(ConverterRegistry converterRegistry) { converterRegistry.addConverter(new StringToTimeZoneConverter()); converterRegistry.addConverter(new ZoneIdToTimeZoneConverter()); converterRegistry.addConverter(new ZonedDateTimeToCalendarConverter()); }
/** * Add converters appropriate for most environments. * @param converterRegistry the registry of converters to add to (must also be castable to ConversionService) * @throws ClassCastException if the converterRegistry could not be cast to a ConversionService */ public static void addDefaultConverters(ConverterRegistry converterRegistry) { addScalarConverters(converterRegistry); addCollectionConverters(converterRegistry); addFallbackConverters(converterRegistry); }
private static void addFallbackConverters(ConverterRegistry converterRegistry) { ConversionService conversionService = (ConversionService) converterRegistry; converterRegistry.addConverter(new ObjectToObjectConverter()); converterRegistry.addConverter(new IdToEntityConverter(conversionService)); converterRegistry.addConverter(new FallbackObjectToStringConverter()); }
@Bean public ConverterRegistry converterRegistry() { return new DefaultConversionService(); }
void configureFilesystemStoreConverters(ConverterRegistry registry);
void configureS3StoreConverters(ConverterRegistry registry);