Every post in this series so far has ended a ChatClient call with .content() -- a string, handed back to whatever prints it. Most real code doesn't want a string. It wants a Java record it can pass to a repository, a List it can iterate, a Map it can look a key up in. This article covers ChatClient.entity(), the API that maps a model's raw JSON text straight into one of those -- and StructuredOutputValidationAdvisor, which is what happens when the model's JSON doesn't actually fit the shape you asked for and something has to decide whether to give up or try again.
Nothing below calls a real LLM. Every test in this article's companion repo drives the real entity() machinery and the real StructuredOutputValidationAdvisor against a hand-written ChatModel that returns a queued, pre-programmed response instead of calling an API -- the same technique, and the same confirmed-by-javap reasoning for why it's legitimate, that the tool-calling article in this series used.
Versions. Spring Boot 4.1.1 and Spring AI 2.0.1, on Java 25 (LTS) — the same baseline as the rest of this series. StructuredOutputValidationAdvisor lives in org.springframework.ai.chat.client.advisor, inside the same spring-ai-client-chat artifact as ToolCallingAdvisor — unlike the Tool Search Advisor pieces in this series' tool-calling article, it needs no separate Maven Central artifact or version pin. It also confirms something worth knowing on its own: Spring AI 2.0's JSON stack is Jackson 3 (tools.jackson.databind), not the classic com.fasterxml.jackson package every older tutorial assumes — visible directly in this advisor's constructor and field signatures.