Skip to Content
author's profile photo Former Member
Former Member

Reverse Converters and Dynamic Attributes Issue

Hi all, I found out a problem using reverse converters, more specifically the off-the-shelf AddressReverseConverter; it seems that dynamic attributes are never populated.

After a lot of debugging, maybe I found out the reason. When calling addressReverseConverter.convert(AddressData addressData), the target AddressModel is instantiated with a "new", not by calling "modelService.create()". This means that the model is not attached to the serviceLayer, and no dynamic attribute handler is effective.

I have attached a simple integration test that explains the problem.

The first test case fails because an addressModel is generated by the converter. The static fields (firstname, lastname) are correctly populated, while the dynamic ones (line1, line2) are not.

The second test case fails for the same reason: addressModel is created by constructor.

The third test case succeeds: addressModel is created through the modelService, and both static and dynamic fields are populated correctly.

I worked the problem around by using the third approach, skipping the converter and using directly the populator. But I am wondering why a bug like that has not been detected and solved before.

 package de.hybris.platform.converters;
 
 import static org.junit.Assert.assertNotNull;
 
 import de.hybris.bootstrap.annotations.IntegrationTest;
 import de.hybris.platform.commercefacades.user.converters.populator.AddressReversePopulator;
 import de.hybris.platform.commercefacades.user.data.AddressData;
 import de.hybris.platform.converters.impl.AbstractPopulatingConverter;
 import de.hybris.platform.core.model.user.AddressModel;
 import de.hybris.platform.servicelayer.ServicelayerTransactionalTest;
 import de.hybris.platform.servicelayer.model.ModelService;
 
 import javax.annotation.Resource;
 
 import org.junit.Before;
 import org.junit.Test;
 
 
 @IntegrationTest
 public class AddressReverseConverterIntegrationTest extends ServicelayerTransactionalTest
 {
     @Resource
     private ModelService modelService;
 
     @Resource
     private AbstractPopulatingConverter<AddressData, AddressModel> addressReverseConverter;
 
     @Resource
     private AddressReversePopulator addressReversePopulator;
 
     private AddressData addressData;
 
     @Before
     public void setup()
     {
         addressData = new AddressData();
         addressData.setFirstName("John");
         addressData.setLastName("Doe");
         addressData.setLine1("Fake road");
         addressData.setLine2("1");
     }
 
     @Test
     public void testReverseConverter()
     {
         final AddressModel addressModel = addressReverseConverter.convert(addressData);
 
         assertNotNull(addressModel.getFirstname());
         assertNotNull(addressModel.getLastname());
 
         assertNotNull(addressModel.getLine1());
         assertNotNull(addressModel.getLine2());
         assertNotNull(addressModel.getStreetname());
         assertNotNull(addressModel.getStreetnumber());
     }
 
     @Test
     public void testReversePopulatorNew()
     {
         final AddressModel addressModel = new AddressModel();
         addressReversePopulator.populate(addressData, addressModel);
 
         assertNotNull(addressModel.getFirstname());
         assertNotNull(addressModel.getLastname());
 
         assertNotNull(addressModel.getLine1());
         assertNotNull(addressModel.getLine2());
         assertNotNull(addressModel.getStreetname());
         assertNotNull(addressModel.getStreetnumber());
     }
 
     @Test
     public void testReversePopulatorCreate()
     {
         final AddressModel addressModel = modelService.create(AddressModel.class);
         addressReversePopulator.populate(addressData, addressModel);
 
         assertNotNull(addressModel.getFirstname());
         assertNotNull(addressModel.getLastname());
 
         assertNotNull(addressModel.getLine1());
         assertNotNull(addressModel.getLine2());
         assertNotNull(addressModel.getStreetname());
         assertNotNull(addressModel.getStreetnumber());
     }
 
     /**
      * @param modelService
      *           the modelService to set
      */
     public void setModelService(final ModelService modelService)
     {
         this.modelService = modelService;
     }
 
     /**
      * @param addressReverseConverter
      *           the addressReverseConverter to set
      */
     public void setAddressReverseConverter(final AbstractPopulatingConverter<AddressData, AddressModel> addressReverseConverter)
     {
         this.addressReverseConverter = addressReverseConverter;
     }
 
     /**
      * @param addressReversePopulator
      *           the addressReversePopulator to set
      */
     public void setAddressReversePopulator(final AddressReversePopulator addressReversePopulator)
     {
         this.addressReversePopulator = addressReversePopulator;
     }
 }
 
Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2016 at 03:17 PM
    -1

    Just run into this issue and its a shame it's not solved yet.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.