entity() is a Spring AI ChatClient method for requesting an LLM response and converting it into a specified Java type. Passing Answer.class replaces String-oriented content extraction with object binding. section 3.4.2
Calling entity(Answer.class) changes prompt handling in two ways:
- Spring AI adds formatting instructions derived from the Answer record and its properties. section 3.4.2
- Spring AI parses the returned JSON object and binds it to Answer. section 3.4.2
Obtaining an Answer object
In a board-game service, change the response operation from content() to entity(Answer.class) so the ChatClient returns an Answer instead of a String. section 3.4.2
