Performance: Entity to DTO mapping
MEDIUM IMPACT
This affects the server response time and the size of data sent to the client, impacting page load speed and interaction responsiveness.
public List<UserDTO> getUsers() {
return userRepository.findAll().stream()
.map(user -> new UserDTO(user.getId(), user.getName()))
.collect(Collectors.toList());
}public List<User> getUsers() {
return userRepository.findAll();
}| Pattern | CPU Overhead | Payload Size | Serialization Time | Verdict |
|---|---|---|---|---|
| Direct entity return | Low | High | High | [X] Bad |
| Manual DTO mapping | Medium | Medium | Medium | [!] OK |
| Library-based DTO mapping | Low | Low | Low | [OK] Good |
| DTO with nested full collections | High | Very High | Very High | [X] Bad |
| DTO with summary fields only | Low | Low | Low | [OK] Good |