0
0
Spring Bootframework~10 mins

MapStruct for automatic mapping 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 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'
AUserController
BUserService
CUserRepository
DUserMapper
Attempts:
3 left
💡 Hint
Common Mistakes
Using service or controller names instead of mapper interface names.
Forgetting to annotate the interface with @Mapper.
2fill in blank
medium

Complete 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'
Amap
Bconvert
Csave
Ddelete
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.
3fill in blank
hard

Fix the error in the mapper implementation retrieval code.

Spring Boot
UserMapper mapper = [1].INSTANCE;
Drag options to blanks, or click blank then click option'
AUserMapperImpl
BUserMapper
CMapperFactory
DMapperInstance
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access INSTANCE from the implementation class name.
Using unrelated class names to get the mapper instance.
4fill in blank
hard

Fill 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'
Aspring
Bdefault
CIGNORE
DWARN
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.
5fill in blank
hard

Fill 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'
Aname
BfullName
Cage
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up source and target field names.
Forgetting to ignore the 'age' field properly.