Skip to Content
Hands-On Microservices with Spring Boot and Spring Cloud
book

Hands-On Microservices with Spring Boot and Spring Cloud

by Magnus Larsson
September 2019
Intermediate to advanced
668 pages
15h 59m
English
Packt Publishing
Content preview from Hands-On Microservices with Spring Boot and Spring Cloud

Declaring a Java bean mapper

So, what about the magic Java bean mapper?

As already mentioned, we use MapStruct to declare our mapper classes. The use of MapStruct is similar in all three core microservices, so we will only go through the source code for the mapper object in the Product microservice. 

The mapper class for the product service looks like this:

@Mapper(componentModel = "spring")public interface ProductMapper {    @Mappings({        @Mapping(target = "serviceAddress", ignore = true)    })    Product entityToApi(ProductEntity entity);    @Mappings({        @Mapping(target = "id", ignore = true),        @Mapping(target = "version", ignore = true)    })    ProductEntity apiToEntity(Product api);}

The following is observed from the preceding code:

  • The entityToApi() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Master Microservices with Spring Boot and Spring Cloud

Master Microservices with Spring Boot and Spring Cloud

In28Minutes Official

Publisher Resources

ISBN: 9781789613476Supplemental Content