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

The following examples show how to use org.springframework.core.convert.converter.ConverterRegistry. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: JodaTimeConverters.java    License: 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 2
Source Project: spring-analysis-note   Source File: DateTimeConverters.java    License: 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 3
Source Project: spring-analysis-note   Source File: ConversionServiceFactory.java    License: 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 4
Source Project: spring-analysis-note   Source File: DefaultConversionService.java    License: 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 5
Source Project: java-technology-stack   Source File: JodaTimeConverters.java    License: 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 6
Source Project: java-technology-stack   Source File: DateTimeConverters.java    License: 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 7
Source Project: java-technology-stack   Source File: ConversionServiceFactory.java    License: 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 8
Source Project: java-technology-stack   Source File: DefaultConversionService.java    License: 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 Project: lams   Source File: JodaTimeConverters.java    License: 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 10
Source Project: lams   Source File: DateTimeConverters.java    License: 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 11
/**
 * 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 12
/**
 * 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 13
Source Project: spring4-understanding   Source File: JodaTimeConverters.java    License: 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 14
Source Project: spring4-understanding   Source File: DateTimeConverters.java    License: 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 15
/**
 * 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 16
/**
 * 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 17
Source Project: sdn-rx   Source File: DefaultReactiveNeo4jClient.java    License: 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 18
Source Project: sdn-rx   Source File: DefaultNeo4jClient.java    License: 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 19
Source Project: sdn-rx   Source File: SingleValueMappingFunctionTest.java    License: 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 20
Source Project: spring-analysis-note   Source File: DateFormatterRegistrar.java    License: 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());
}
 
Example 21
Source Project: spring-analysis-note   Source File: DefaultConversionService.java    License: MIT License 5 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));
	converterRegistry.addConverter(new StringToTimeZoneConverter());
	converterRegistry.addConverter(new ZoneIdToTimeZoneConverter());
	converterRegistry.addConverter(new ZonedDateTimeToCalendarConverter());

	converterRegistry.addConverter(new ObjectToObjectConverter());
	converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
	converterRegistry.addConverter(new FallbackObjectToStringConverter());
	converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
}
 
Example 22
Source Project: spring-analysis-note   Source File: DefaultConversionService.java    License: MIT License 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 Project: java-technology-stack   Source File: DateFormatterRegistrar.java    License: 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());
}
 
Example 24
Source Project: java-technology-stack   Source File: DefaultConversionService.java    License: MIT License 5 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));
	converterRegistry.addConverter(new StringToTimeZoneConverter());
	converterRegistry.addConverter(new ZoneIdToTimeZoneConverter());
	converterRegistry.addConverter(new ZonedDateTimeToCalendarConverter());

	converterRegistry.addConverter(new ObjectToObjectConverter());
	converterRegistry.addConverter(new IdToEntityConverter((ConversionService) converterRegistry));
	converterRegistry.addConverter(new FallbackObjectToStringConverter());
	converterRegistry.addConverter(new ObjectToOptionalConverter((ConversionService) converterRegistry));
}
 
Example 25
Source Project: java-technology-stack   Source File: DefaultConversionService.java    License: MIT License 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 26
Source Project: ambari-logsearch   Source File: AbstractConverterAware.java    License: 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 27
/**
 * Add converters useful for most Spring Boot applications.
 *
 * @param registry 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 addApplicationConverters(ConverterRegistry registry) {
    addDelimitedStringConverters(registry);
    registry.addConverter(new StringToDurationConverter());
    registry.addConverter(new DurationToStringConverter());
    registry.addConverter(new NumberToDurationConverter());
    registry.addConverter(new DurationToNumberConverter());
    registry.addConverter(new StringToDataSizeConverter());
    registry.addConverter(new NumberToDataSizeConverter());
    registry.addConverterFactory(new StringToEnumIgnoringCaseConverterFactory());
}
 
Example 28
/**
 * 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 29
Source Project: lams   Source File: DateFormatterRegistrar.java    License: GNU General Public License v2.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 30
/**
 * 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));
	}
}