use of io.micronaut.core.convert.TypeConverterRegistrar in project micronaut-core by micronaut-projects.
the class DefaultApplicationContext method initializeTypeConverters.
/**
* @param beanContext The bean context
*/
protected void initializeTypeConverters(BeanContext beanContext) {
Collection<BeanRegistration<TypeConverter>> typeConverters = beanContext.getBeanRegistrations(TypeConverter.class);
for (BeanRegistration<TypeConverter> typeConverterRegistration : typeConverters) {
TypeConverter typeConverter = typeConverterRegistration.getBean();
List<Argument<?>> typeArguments = typeConverterRegistration.getBeanDefinition().getTypeArguments(TypeConverter.class);
if (typeArguments.size() == 2) {
Class source = typeArguments.get(0).getType();
Class target = typeArguments.get(1).getType();
if (source != null && target != null && !(source == Object.class && target == Object.class)) {
getConversionService().addConverter(source, target, typeConverter);
}
}
}
Collection<TypeConverterRegistrar> registrars = beanContext.getBeansOfType(TypeConverterRegistrar.class);
for (TypeConverterRegistrar registrar : registrars) {
registrar.register(conversionService);
}
}
Aggregations