Java Code Examples for org.springframework.core.convert.support.GenericConversionService#convert()
The following examples show how to use
org.springframework.core.convert.support.GenericConversionService#convert() .
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: GenericMapConverterTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Test public void noDelegateMapConversion() { GenericConversionService conversionService = new GenericConversionService(); GenericMapConverter mapConverter = new GenericMapConverter(conversionService); conversionService.addConverter(mapConverter); @SuppressWarnings("unchecked") Map<String, String> result = conversionService.convert("foo = bar, wizz = jogg", Map.class); assertThat(result, hasEntry("foo", "bar")); assertThat(result, hasEntry("wizz", "jogg")); assertThat( conversionService.canConvert(TypeDescriptor.valueOf(String.class), TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(GenericMapConverterTests.class), TypeDescriptor.valueOf(Integer.class))), is(false)); }
Example 2
Source File: ConvertUtil.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
/** * Convenience operation for converting a source object to the specified targetType. * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, Class<T> targetType) { if (source == null) { return null; } if (ClassUtil.isAssignableValue(targetType, source)) { return (T) source; } GenericConversionService conversionService = MicaConversionService.getInstance(); return conversionService.convert(source, targetType); }
Example 3
Source File: ConvertUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 5 votes |
/** * Convenience operation for converting a source object to the specified targetType. * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, Class<T> targetType) { if (source == null) { return null; } if (ClassUtil.isAssignableValue(targetType, source)) { return (T) source; } GenericConversionService conversionService = BladeConversionService.getInstance(); return conversionService.convert(source, targetType); }
Example 4
Source File: ConvertUtil.java From mica with GNU Lesser General Public License v3.0 | 3 votes |
/** * Convenience operation for converting a source object to the specified targetType, * where the target type is a descriptor that provides additional conversion context. * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param sourceType the source type * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } GenericConversionService conversionService = MicaConversionService.getInstance(); return (T) conversionService.convert(source, sourceType, targetType); }
Example 5
Source File: ConvertUtil.java From mica with GNU Lesser General Public License v3.0 | 3 votes |
/** * Convenience operation for converting a source object to the specified targetType, * where the target type is a descriptor that provides additional conversion context. * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and * encapsulates the construction of the source type descriptor using * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, TypeDescriptor targetType) { if (source == null) { return null; } GenericConversionService conversionService = MicaConversionService.getInstance(); return (T) conversionService.convert(source, targetType); }
Example 6
Source File: ConvertUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 3 votes |
/** * Convenience operation for converting a source object to the specified targetType, * where the target type is a descriptor that provides additional conversion context. * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param sourceType the source type * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } GenericConversionService conversionService = BladeConversionService.getInstance(); return (T) conversionService.convert(source, sourceType, targetType); }
Example 7
Source File: ConvertUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 3 votes |
/** * Convenience operation for converting a source object to the specified targetType, * where the target type is a descriptor that provides additional conversion context. * Simply delegates to {@link #convert(Object, TypeDescriptor, TypeDescriptor)} and * encapsulates the construction of the source type descriptor using * {@link TypeDescriptor#forObject(Object)}. * @param source the source object * @param targetType the target type * @param <T> 泛型标记 * @return the converted value * @throws IllegalArgumentException if targetType is {@code null}, * or sourceType is {@code null} but source is not {@code null} */ @Nullable public static <T> T convert(@Nullable Object source, TypeDescriptor targetType) { if (source == null) { return null; } GenericConversionService conversionService = BladeConversionService.getInstance(); return (T) conversionService.convert(source, targetType); }