SAP Hybris Tutorial – Converters and Populators | Unit 10
Overview
Data objects (you could say as DTO (Data Transfer Object)) are constructed from Models or other Service Layer objects using Converters and Populators. Converters create new instances of Data objects and call Populators to populate these data objects.
The data objects are produced at the Facade layer. Please view the diagram flow below to imagine easily.
Sap Hybris provides converters and populators to buildup DTOs in a most dynamic and independent way. However, it requires an understanding of configurations.
Converters
Each converter has an input (source) and output (target). Normally, the input (source) is from the Service layer and the output (target) is the DTO that will be produced and returned to the Controller layer.
Populators
Each converter can have one or multiple populators, each populator has its own purpose to fulfill data for the DTO.
Configurable Populators and Data Options
For Objects store complex data need multiple populators to populate data for the DTO, and on different requests will respond to different data.
Example: The products display on the product detail page (PDP) will request a lot of product attributes than the products display on the product listing page (PLP).
So, depending on the circumstances we will have proper data options corresponding with the configured populators.
Ref: Converters and Populators
Practice
We will add a new “origin” property to the product model. This “origin” property contains the origin information of the product such as:
- manufacturerName(string)
- address(String)
- countryName(String).
- productCode(String)
- catalog
Step 1: Creating a new Origin Model.
Step 2: Adding new data into the productData DTO
Step 3: Creating a converter an populator to populate the new origin data for productData DTO
Step 4: Updating the Ui to display new Origin data
Step 5: Building and starting server
Step 6: Adding some sample data for this new “Origin” object
Step 7: Verify the implementation.
You can watch the video to compare your results.
Good jobs. You have done a crucial technique. Keep up the good work.!
Happy coding.! <3