liveBook · Manning

Java record

As explained in Spring AI in Action

A Java record is a restricted Java class for declaring compact immutable data-carrier types.

A Java record is a restricted Java class for declaring compact immutable data-carrier types. In a Spring AI REST application, Question carries the submitted question and Answer carries the generated answer; each currently contains one String property and can gain more properties as the application evolves. section 1.1.2

Request and response records

public record Question(String question) { }\npublic record Answer(String answer) { }\n\nThe service reads the submitted value with question.question() and wraps the generated text with new Answer(answerText). section 1.1.2

package com.example.boardgamebuddy;

public record Question(String question) {
}

Inspect the compact Question declaration used as the REST service input. section 1.1.2

How Spring AI in Action covers it

How deep it goes
Defines single-property records and demonstrates access and construction, but does not develop advanced record features.
Examples
Uses Question(String question) and Answer(String answer) as request and generated-answer carriers.
What it assumes
Assumes Java and Spring application structure while demonstrating record usage through a concrete service flow.
What you can do after
Builds compact Java data carriers for application inputs and outputs.
How it connects
Connects Java classes and records to REST APIs, Spring AI, ChatClient, and LLM-generated answers.

Also explained in

Compare how 4 books explain Java record →

Related concepts

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