liveBook · Manning

Converter

As explained in Spring in Action, Sixth Edition

A Spring Converter is a class implementing the Converter interface to transform a value from one type into another during data binding.

A Spring Converter bridges two types during data binding. It implements Converter and its convert() method, turning submitted values such as ingredient IDs into richer domain objects. section 2.2

Converting ingredient IDs

A checkbox submission may contain ["FLTO", "GRBF", "LETC"], while Taco expects a List<Ingredient>. IngredientByIdConverter implements Converter<String, Ingredient>, stores ingredients in a Map, and uses each submitted ID to return the matching Ingredient. Annotating the class with @Component makes it discoverable; Spring Boot automatically registers Converter beans with Spring MVC for request-parameter binding. The example uses hardcoded ingredients and defers database-backed lookup. section 2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains interface implementation, lookup logic, bean discovery, and automatic registration, but defers database-backed conversion.
Examples
Uses taco ingredient checkboxes, ingredient IDs, a Map lookup, and IngredientByIdConverter as concrete implementation artifacts.
What it assumes
Assumes form fields and domain properties participate in binding, while demonstrating the converter interface and component annotation directly.
What you can do after
Build it from scratch by implementing Converter<String, Ingredient> and registering the class as a Spring component.
How it connects
Connects data binding, Spring MVC, form submission, domain objects, and Spring Boot autoconfiguration.

Also explained in

Compare how 4 books explain converter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.