Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a MapStruct mapper interface.
Spring Boot
import org.mapstruct.Mapper; @Mapper public interface [1] { // mapping methods }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using service or controller names instead of mapper interface names.
Forgetting to annotate the interface with @Mapper.
✗ Incorrect
The interface annotated with @Mapper should be named as a Mapper, like UserMapper.
2fill in blank
mediumComplete the code to define a mapping method from UserEntity to UserDTO.
Spring Boot
UserDTO [1](UserEntity userEntity); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names like 'save' or 'delete' which are unrelated to mapping.
Using generic names that do not indicate mapping.
✗ Incorrect
MapStruct mapping methods are often named 'map' to indicate conversion.
3fill in blank
hardFix the error in the mapper implementation retrieval code.
Spring Boot
UserMapper mapper = [1].INSTANCE; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access INSTANCE from the implementation class name.
Using unrelated class names to get the mapper instance.
✗ Incorrect
MapStruct generates an INSTANCE field in the mapper interface for accessing the implementation.
4fill in blank
hardFill both blanks to define a mapper with component model 'spring' and specify unmapped target policy to ignore.
Spring Boot
@Mapper(componentModel = "[1]", unmappedTargetPolicy = ReportingPolicy.[2]) public interface UserMapper { UserDTO map(UserEntity userEntity); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' instead of 'spring' for componentModel when integrating with Spring.
Using WARN instead of IGNORE for unmappedTargetPolicy when you want to suppress warnings.
✗ Incorrect
Setting componentModel to 'spring' allows Spring to manage the mapper bean. Setting unmappedTargetPolicy to IGNORE suppresses warnings for unmapped fields.
5fill in blank
hardFill all three blanks to create a mapping method that maps 'name' from source to 'fullName' in target and ignores 'age'.
Spring Boot
@Mapping(source = "[1]", target = "[2]") @Mapping(target = "[3]", ignore = true) UserDTO map(UserEntity userEntity);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up source and target field names.
Forgetting to ignore the 'age' field properly.
✗ Incorrect
The 'name' field from source maps to 'fullName' in target. The 'age' field is ignored in mapping.