Search code examples
sap-commerce-cloudapache-commons-lang3

the best way to clone hybris beans?


I needed to clone the hybris bean "ProductData", and I couldn't find something OOTB from Hybris that helps with this.

And since hybris beans don't implement Cloneable and don't have constructors, it seems to me that there are only two ways left, either by creating a custom cloning method witch require a lot of dev, or through serialization/deserialization.

Is there another way to do that? and does Hybris provides something OOTB for this? or else is the serialization/deserialization a good approach (in term of performance) for this since there is the SerializationUtils from apache that I can use?


Solution

  • Hi You can directly Inject dataMapper bean in your controller or in service.

    import de.hybris.platform.webservicescommons.mapping.DataMapper;
    @Autowired
    private DataMapper dataMapper;
    
    dataMapper.map(e, ProductData.class)
    

    enter image description here