A data transfer object (DTO) carries structured data across an application boundary, such as between a REST endpoint and a client. It can model either an HTTP request body or a response body. section 10.3.1 section 13.3
In a Spring REST endpoint, a DTO can serve either direction:
- Return a Country object to send its name and population in the response. section 10.3.1
- Accept a TransferRequest object to model the data in a transfer request body. section 13.3
Listing 13.10 The TransferRequest data transfer object modeling the HTTP request body
public class TransferRequest {
private long senderAccountId;
private long receiverAccountId;
private BigDecimal amount;
// Omitted code
}The TransferRequest DTO holds the sender account ID, receiver account ID, and transfer amount. section 13.3
A DTO returned as JSON
Returning a Country for France with population 67 produces a response body with the attributes "name" and "population". A collection of Country objects can likewise be returned as a JSON array. section 10.3.1









