A converter interface defines a single, reusable contract for turning a value of one type into another. Java itself has no built-in Converter type in the standard library, so the name usually refers to the Spring Framework interface org.springframework.core.convert.converter.Converter<S, T>, which has one method, convert. You can also express the same idea with java.util.function.Function, Guava's Converter, or JPA's AttributeConverter.
The value of the abstraction is that conversion logic lives in one tested class instead of being scattered through controllers and services. This article uses Spring Framework 6 and Spring Boot 3 or later.
Converter<S, T> interfaceConverterFactory, GenericConverter and FormatterConverter<S, T> interfaceThe interface is deliberately small. It converts a source object of type S into a target object of type T.
The implementation must be thread-safe and stateless, because Spring shares one instance. It is one-directional: this converter turns a String into a LocalDate, and a second converter is needed for the reverse. If conversion fails, throw an exception such as IllegalArgumentException, and Spring wraps it in a ConversionFailedException.
Spring's ConversionService holds every registered converter and picks the right one by source and target type.
@RequestParam, @PathVariable and form fields to method parameters.@Value injection and @ConfigurationProperties binding use it to turn strings into durations, URIs, enums and your own types.Converter bean in the web conversion service, so the @Component above is enough for web binding.A request to /reports?since=2026-01-15 reaches the method with a LocalDate, with no manual parsing in the controller.
ConverterFactory, GenericConverter and FormatterWhen one converter class is not enough, Spring offers more flexible variants.
| Interface | Use it when |
|---|---|
Converter<S, T> | You convert one source type to one target type |
ConverterFactory<S, R> | You convert to a whole family of targets, such as any Enum subtype |
GenericConverter | You need several type pairs or access to field annotations and generics |
Formatter<T> | You convert between String and a type with locale awareness, for example dates and currencies |
For parsing and printing text, a Formatter is usually the better choice than a raw Converter<String, T>, because it receives the Locale. Register converters and formatters yourself with WebMvcConfigurer:
You do not need Spring to apply the pattern. A Function<S, T> is the lightest option for one-way conversion, and it composes with andThen.
Guava provides com.google.common.base.Converter<A, B>, which is bidirectional through doForward and doBackward and offers reverse(). JPA defines AttributeConverter<X, Y> for mapping entity attributes to database columns, and MapStruct generates type-safe mappers at compile time when you convert between whole objects such as entities and DTOs.
null and blank input, and test it.StringToLocalDateConverter, so a reader knows what they do.convert directly, since no framework is needed.Converter interface in the Java standard library?No. java.util.function.Function serves the same purpose. The well-known Converter types come from Spring, Guava and JPA.
Converter and Formatter?A Converter maps one type to another. A Formatter converts between a type and String and is locale-aware, which suits dates, numbers and currencies.
Declare it as a bean, for example with @Component, and Spring Boot adds it to the web conversion service. You can also register it in WebMvcConfigurer.addFormatters.
Converter convert in both directions?Spring's interface is one-way, so write a second converter for the reverse. Guava's Converter is bidirectional.
The Converter interface isolates type conversion behind one method. In Spring it drives data binding and configuration properties, and variants such as ConverterFactory, GenericConverter and Formatter cover advanced cases. In plain Java, a Function gives the same result without a framework.