TypeConverterConverter Class — spring-boot Architecture
Architecture documentation for the TypeConverterConverter class in BindConverter.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java lines 189–253
private static class TypeConverterConverter implements ConditionalGenericConverter {
private static final Set<Class<?>> EXCLUDED_EDITORS;
static {
Set<Class<?>> excluded = new HashSet<>();
excluded.add(CustomNumberEditor.class);
excluded.add(CustomBooleanEditor.class);
excluded.add(FileEditor.class);
EXCLUDED_EDITORS = Collections.unmodifiableSet(excluded);
}
private final @Nullable Consumer<PropertyEditorRegistry> initializer;
// SimpleTypeConverter is not thread-safe to use for conversion but we can use it
// in a thread-safe way to check if conversion is possible.
private final SimpleTypeConverter matchesOnlyTypeConverter;
TypeConverterConverter(@Nullable Consumer<PropertyEditorRegistry> initializer) {
this.initializer = initializer;
this.matchesOnlyTypeConverter = createTypeConverter();
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
return Set.of(new ConvertiblePair(String.class, Object.class),
new ConvertiblePair(String.class, Resource[].class),
new ConvertiblePair(String.class, Collection.class));
}
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
Class<?> type = targetType.getType();
if (type == null || type == Object.class || Map.class.isAssignableFrom(type)) {
return false;
}
if (Collection.class.isAssignableFrom(type)) {
TypeDescriptor elementType = targetType.getElementTypeDescriptor();
if (elementType == null || (!Resource.class.isAssignableFrom(elementType.getType()))) {
return false;
}
}
PropertyEditor editor = this.matchesOnlyTypeConverter.getDefaultEditor(type);
if (editor == null) {
editor = this.matchesOnlyTypeConverter.findCustomEditor(type, null);
}
if (editor == null && String.class != type) {
editor = BeanUtils.findEditorByConvention(type);
}
return (editor != null && !EXCLUDED_EDITORS.contains(editor.getClass()));
}
@Override
public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return createTypeConverter().convertIfNecessary(source, targetType.getType(), targetType);
}
private SimpleTypeConverter createTypeConverter() {
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
if (this.initializer != null) {
this.initializer.accept(typeConverter);
}
return typeConverter;
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free