September 2019
Intermediate to advanced
668 pages
15h 59m
English
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: