Performance: Response DTO for output
This affects the size and structure of data sent from server to client, impacting network load and client rendering speed.
Jump into concepts and practice - no test required
public class UserResponse { private Long id; private String username; private String email; // getters and setters }
public class UserResponse { private Long id; private String username; private String password; private String email; private List<Order> orders; private List<Role> roles; // getters and setters }
| Pattern | Payload Size | Network Impact | Client Parsing | Verdict |
|---|---|---|---|---|
| Large DTO with sensitive and nested data | 50-100kb | High latency | Slow parsing | [X] Bad |
| Minimal DTO with essential fields only | 10-20kb | Low latency | Fast parsing | [OK] Good |
Response DTO in a Spring Boot application?public record ProductResponse(String name, double price) {}
@GetMapping("/product")
public ProductResponse getProduct() {
return new ProductResponse("Book", 12.5);
}name and price, which map directly to JSON keys.public class UserResponse {
private String username;
public UserResponse(String username) {}
public String getUsername() { return username; }
}id and email, hiding the password. Which approach is best in Spring Boot?