Recall & Review
beginner
What is MapStruct in Spring Boot?
MapStruct is a code generator that simplifies mapping between Java objects, especially between DTOs and entities, by generating type-safe mappers at compile time.
Click to reveal answer
beginner
How does MapStruct improve mapping compared to manual mapping?
MapStruct generates mapping code automatically, reducing boilerplate, avoiding runtime errors, and improving performance by doing mapping at compile time instead of reflection.
Click to reveal answer
beginner
What annotation do you use to define a MapStruct mapper interface?
You use the @Mapper annotation on an interface to tell MapStruct to generate the implementation for mapping methods defined inside.
Click to reveal answer
intermediate
How do you get an instance of a MapStruct mapper in your Spring Boot application?
You can add componentModel = "spring" in @Mapper to make MapStruct generate a Spring bean, then inject it with @Autowired or constructor injection.
Click to reveal answer
intermediate
What happens if source and target fields have different names in MapStruct?
You can use @Mapping annotation on the method to specify how fields with different names map to each other, by defining source and target explicitly.
Click to reveal answer
What does MapStruct generate for you?
✗ Incorrect
MapStruct generates Java code at compile time to map between objects, avoiding runtime reflection.
Which annotation marks an interface as a MapStruct mapper?
✗ Incorrect
The @Mapper annotation tells MapStruct to generate the implementation for the interface.
How do you make a MapStruct mapper a Spring bean?
✗ Incorrect
Setting componentModel = "spring" in @Mapper makes MapStruct generate a Spring bean.
If source and target fields have different names, how do you map them?
✗ Incorrect
You specify field mappings explicitly with @Mapping(source = ..., target = ...).
What is a main benefit of MapStruct over manual mapping?
✗ Incorrect
MapStruct generates code at compile time, improving performance and safety.
Explain how MapStruct helps in mapping between DTOs and entities in Spring Boot.
Think about how MapStruct reduces manual coding and errors.
You got /4 concepts.
Describe how you handle mapping fields with different names using MapStruct.
Focus on the annotation that lets you define explicit field mappings.
You got /3 concepts.