/** * Removes the converter being able to convert any object into an {@link Optional} from the given * {@link ConversionService} in case we're running on Java 8. * * @param conversionService must not be {@literal null}. */ public static void potentiallyRemoveOptionalConverter(ConfigurableConversionService conversionService) { ClassLoader classLoader = JpaQueryExecution.class.getClassLoader(); if (ClassUtils.isPresent("java.util.Optional", classLoader)) { try { Class<?> optionalType = ClassUtils.forName("java.util.Optional", classLoader); conversionService.removeConvertible(Object.class, optionalType); } catch (ClassNotFoundException | LinkageError o_O) {} } } }
public static void potentiallyRemoveOptionalConverter( ConfigurableConversionService conversionService) { ClassLoader classLoader = MybatisQueryExecution.class.getClassLoader(); if (ClassUtils.isPresent("java.util.Optional", classLoader)) { try { Class<?> optionalType = ClassUtils.forName("java.util.Optional", classLoader); conversionService.removeConvertible(Object.class, optionalType); } catch (ClassNotFoundException | LinkageError o_O) { } } }
/** * Removes the converter being able to convert any object into an {@link Optional} from the given * {@link ConversionService} in case we're running on Java 8. * * @param conversionService must not be {@literal null}. */ public static void potentiallyRemoveOptionalConverter(ConfigurableConversionService conversionService) { ClassLoader classLoader = JpaQueryExecution.class.getClassLoader(); if (ClassUtils.isPresent("java.util.Optional", classLoader)) { try { Class<?> optionalType = ClassUtils.forName("java.util.Optional", classLoader); conversionService.removeConvertible(Object.class, optionalType); } catch (ClassNotFoundException | LinkageError o_O) {} } } }
/** * Registers converters for wrapper types found on the classpath. * * @param conversionService must not be {@literal null}. */ public static void registerConvertersIn(ConfigurableConversionService conversionService) { Assert.notNull(conversionService, "ConversionService must not be null!"); conversionService.removeConvertible(Collection.class, Object.class); if (GUAVA_PRESENT) { conversionService.addConverter(new NullableWrapperToGuavaOptionalConverter(conversionService)); } if (JDK_8_PRESENT) { conversionService.addConverter(new NullableWrapperToJdk8OptionalConverter(conversionService)); conversionService.addConverter(new NullableWrapperToCompletableFutureConverter(conversionService)); } if (SCALA_PRESENT) { conversionService.addConverter(new NullableWrapperToScalaOptionConverter(conversionService)); } if (JAVASLANG_PRESENT) { conversionService.addConverter(new NullableWrapperToJavaslangOptionConverter(conversionService)); conversionService.addConverter(JavaslangCollections.FromJavaConverter.INSTANCE); } if (VAVR_PRESENT) { conversionService.addConverter(new NullableWrapperToVavrOptionConverter(conversionService)); conversionService.addConverter(VavrCollections.FromJavaConverter.INSTANCE); } conversionService.addConverter(new NullableWrapperToFutureConverter(conversionService)); conversionService.addConverter(IterableToStreamableConverter.INSTANCE); }