0
0
Spring Bootframework~10 mins

Nested DTOs in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AaddressDto
BaddressDTO
Caddress
DaddressData
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.
2fill in blank
medium

Complete 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'
Aaddress
Baddr
CaddressDTO
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter and the field.
Forgetting to assign the parameter to the field.
3fill in blank
hard

Fix 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'
Aaddress
BgetAddress
CfetchAddress
DretrieveAddress
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the getter method the same as the field.
Using non-standard prefixes like 'fetch' or 'retrieve'.
4fill in blank
hard

Fill 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'
AAddressDTO
Baddress
CString
Dcity
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.
5fill in blank
hard

Fill 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'
AuserDTO
BAddress
CAddressDTO
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent parameter names.
Incorrect getter method names for nested DTO.