Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a nested DTO class inside the main DTO.
Spring Boot
public class UserDTO { private String name; private AddressDTO [1]; public static class AddressDTO { private String city; private String zipCode; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the field name without camelCase.
Using unrelated names that do not represent the nested DTO.
✗ Incorrect
The field name for the nested DTO should be 'address' to represent the AddressDTO object inside UserDTO.
2fill in blank
mediumComplete the constructor to initialize the nested DTO field.
Spring Boot
public UserDTO(String name, AddressDTO [1]) { this.name = name; this.address = [1]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter and the field.
Forgetting to assign the parameter to the field.
✗ Incorrect
The constructor parameter and assignment should use the same field name 'address' to initialize the nested DTO.
3fill in blank
hardFix the error in the getter method for the nested DTO field.
Spring Boot
public AddressDTO [1]() { return address; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the getter method the same as the field.
Using non-standard prefixes like 'fetch' or 'retrieve'.
✗ Incorrect
The getter method for a field named 'address' should be named 'getAddress' following Java bean conventions.
4fill in blank
hardFill both blanks to create a nested DTO with Lombok annotations for getters and setters.
Spring Boot
@Data public class UserDTO { private String name; private [1] [2]; @Data public static class AddressDTO { private String city; private String zipCode; } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using primitive types instead of the nested DTO type.
Using incorrect field names that do not match the nested DTO.
✗ Incorrect
The field type is 'AddressDTO' and the field name is 'address' to represent the nested DTO with Lombok @Data annotation.
5fill in blank
hardFill all three blanks to map nested DTO fields in a Spring Boot controller method.
Spring Boot
@PostMapping("/user") public ResponseEntity<String> createUser(@RequestBody UserDTO [1]) { String city = [2].get[3]().getCity(); // process city return ResponseEntity.ok("User from " + city); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Incorrect getter method names for nested DTO.
✗ Incorrect
The method parameter is 'userDTO', then we call 'userDTO.getAddress()' to access the nested DTO and get the city.