Map model attributes to DTO properties once -- get the Populator class, its Spring bean, and a new or extended converter wiring.
🔒 Your code never leaves your browser — everything is generated locally from templates, no AI, no server round-trip.
trainingcore/src/com/prospect2p/core/populators/ProductPopulator.javapackage com.prospect2p.core.populators;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.converters.Populator;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
public class ProductPopulator implements Populator<ProductModel, ProductData> {
@Override
public void populate(final ProductModel source, final ProductData target) throws ConversionException {
// TODO: no field mappings configured
}
}
A Populator in SAP Commerce (Hybris) is a small class implementing Populator<Source, Target> with one method, populate(source, target), that copies/derives fields from a model (or another DTO) onto a target DTO. A Converter composes one or more populators and the actual "new instance" creation into a single reusable conversion step -- typically a bean extending/parented on AbstractPopulatingConverter.
This split exists so individual field-mapping concerns stay small and composable: a converter's populator list can mix OOTB populators with your own, and the same populator can be reused across multiple converters that happen to need the same mapping.
Use a new populator + converter when you're introducing a DTO that doesn't already have an OOTB converter -- e.g. a custom facade-layer Data object for a new feature.
Use "extend an existing converter" when you want to add one or two extra fields onto an OOTB DTO (like ProductData) without forking the whole OOTB converter -- appending your populator onto its existing list via Spring's list merge keeps every other OOTB field mapping intact.
Populators are reusable across every converter/controller that needs the same mapping and are independently unit-testable. Scattering the same source->target field logic across multiple controllers is exactly what the populator/converter pattern exists to avoid.
It implements the boilerplate of Converter<Source, Target>: creating a new target instance (via targetClass), then running every populator in its list against (source, target) in order. Your converter bean just supplies targetClass and the populator list.
Redeclare the same bean id with itself as parent and a populators list using merge="true" -- Spring appends your new <ref> to the inherited list rather than replacing it. That's what "extend an existing converter" mode generates here.
Not directly -- populators are meant to be flat, composable units invoked by a converter's list. If one mapping depends on another, either combine them in one populator or make sure the converter's list order puts the dependency first.
It's not required by the compiler, but yes -- it's good practice and this generator includes it, since it immediately flags a typo in the method signature (wrong generic types) as a compile error instead of a silently-unused method.