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

The following examples show how to use org.springframework.core.convert.converter.ConverterRegistry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultConversionService.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
	}
}
 
Example #2
Source File: ConversionServiceFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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");
			}
		}
	}
}
 
Example #3
Source File: DefaultConversionService.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
	}
}
 
Example #4
Source File: DateTimeConverters.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #5
Source File: JodaTimeConverters.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #6
Source File: JodaTimeConverters.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #7
Source File: DateTimeConverters.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #8
Source File: DefaultConversionService.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Add common 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));

	converterRegistry.addConverter(new StreamConverter(conversionService));
}
 
Example #9
Source File: ConversionServiceFactory.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
			}
		}
	}
}
 
Example #10
Source File: ConversionServiceFactory.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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(@Nullable 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");
			}
		}
	}
}
 
Example #11
Source File: DateTimeConverters.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example #12
Source File: JodaTimeConverters.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example #13
Source File: DefaultConversionService.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Add common 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));

	converterRegistry.addConverter(new StreamConverter(conversionService));
}
 
Example #14
Source File: ConversionServiceFactory.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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(@Nullable 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");
			}
		}
	}
}
 
Example #15
Source File: DateTimeConverters.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example #16
Source File: JodaTimeConverters.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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());
}
 
Example #17
Source File: DefaultConversionService.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
	}
}
 
Example #18
Source File: AbstractConversionServiceAwareConverter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@PostConstruct
private void register() {
    if (conversionService instanceof ConverterRegistry) {
        ((ConverterRegistry) conversionService).addConverter(this);
    } else {
        throw new IllegalStateException("Can't register Converter to ConverterRegistry");
    }
}
 
Example #19
Source File: DefaultConversionService.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #20
Source File: DateFormatterRegistrar.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #21
Source File: DefaultConversionServiceTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #22
Source File: DefaultConversionService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #23
Source File: DefaultConversionService.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
	}
}
 
Example #24
Source File: FilesystemStoreConfiguration.java    From spring-content with Apache License 2.0 5 votes vote down vote up
protected void addConverters(ConverterRegistry registry) {
	if (configurers == null)
		return;

	for (FilesystemStoreConfigurer configurer : configurers) {
		configurer.configureFilesystemStoreConverters(registry);
	}
}
 
Example #25
Source File: S3StoreConfiguration.java    From spring-content with Apache License 2.0 5 votes vote down vote up
private void addConverters(ConverterRegistry registry) {
	if (configurers == null)
		return;

	for (S3StoreConfigurer configurer : configurers) {
		configurer.configureS3StoreConverters(registry);
	}
}
 
Example #26
Source File: DefaultReactiveNeo4jClient.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
DefaultReactiveNeo4jClient(Driver driver) {

		this.driver = driver;
		this.typeSystem = driver.defaultTypeSystem();
		this.conversionService = new DefaultConversionService();
		new Neo4jConversions().registerConvertersIn((ConverterRegistry) conversionService);
	}
 
Example #27
Source File: BladeFeignAutoConfiguration.java    From blade-tool with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * blade enum 《-》 String 转换配置
 * @param conversionService ConversionService
 * @return SpringMvcContract
 */
@Bean
public Contract feignContract(@Qualifier("mvcConversionService") ConversionService conversionService) {
	ConverterRegistry converterRegistry =  ((ConverterRegistry) conversionService);
	converterRegistry.addConverter(new EnumToStringConverter());
	converterRegistry.addConverter(new StringToEnumConverter());
	return new BladeSpringMvcContract(new ArrayList<>(), conversionService);
}
 
Example #28
Source File: DefaultNeo4jClient.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
DefaultNeo4jClient(Driver driver) {

		this.driver = driver;
		this.typeSystem = driver.defaultTypeSystem();

		this.conversionService = new DefaultConversionService();
		new Neo4jConversions().registerConvertersIn((ConverterRegistry) conversionService);
	}
 
Example #29
Source File: SingleValueMappingFunctionTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
SingleValueMappingFunctionTest(@Mock TypeSystem typeSystem, @Mock Record record) {
	this.typeSystem = typeSystem;
	this.record = record;
	this.conversionService = new DefaultConversionService();
	new Neo4jConversions().registerConvertersIn((ConverterRegistry) this.conversionService);

}
 
Example #30
Source File: DateFormatterRegistrar.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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());
}