cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Data Mapper doesn't work for a custom attribute

Former Member
0 Kudos
2,034

Hello All ,

Iam facing an issue that data mapper doesn't map the field i have just added ,

Steps i have done :-

1) i added erpCustomerCode attribute into AddressWsDTO

 /** <i>Generated property</i> for <code>AddressWsDTO.erpCustomerCode</code> property defined at extension <code>myWebservices</code>. */
         
     private String erpCustomerCode;


2)added the same attribute into addressData

 /** <i>Generated property</i> for <code>AddressData.erpCustomerCode</code> property defined at extension <code>myFacades</code>. */
         
     private String erpCustomerCode;
 

3) change the code inside the mapper

 validate(address, "address", getAddressDTOValidator());
     final AddressData addressData = getDataMapper().map(address, AddressData.class,
             "erpCustomerCode,firstName,lastName,titleCode,line1,line2,town,postalCode,country(isocode),region(isocode),defaultAddress,phone");
     addressData.setShippingAddress(true);
     addressData.setVisibleInAddressBook(true);
     final String erpCode = erpUserService.createErpUser(address);
     **addressData.setErpCustomerCode(erpCode);**
     getUserFacade().addAddress(addressData);
     if (addressData.isDefaultAddress())
     {
         getUserFacade().setDefaultAddress(addressData);
     }

     return getDataMapper().map(addressData, AddressWsDTO.class, fields);

but i always get this response

 {
   "country": {
     "isocode": "xx"
   },
   "defaultAddress": false,
   "firstName": "xxxx",
   "id": "xxxx",
   "lastName": "xxxx",
   "line1": "xx",
   "line2": "",
   "phone": "xxx",
   "postalCode": "xxx",
   "region": {
     "isocode": "xxx"
   },
   "town": "xxx"
 }


i have tried to debug but it gives no error in the mapping ,, any idea why my added field (erpCustomerCode) isn't added ?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Make Sure you have mapped your custom attribute for the Basic, Default and Full level mapping in dto-level-mappings-v2-spring.xml.

as per OOTB the below attributes called for Default

     <property name="dtoClass"
               value="de.hybris.platform.commercewebservicescommons.dto.user.AddressWsDTO"/>
     <property name="levelMapping">
         <map>
             <entry key="BASIC" value="id"/>
             <entry key="DEFAULT"
                    value="BASIC,firstName,lastName,line1,line2,postalCode,phone,town,region,country,defaultAddress"/>
             <entry key="FULL"
                    value="region(FULL),lastName,titleCode,phone,companyName,country(FULL),id,title,postalCode,email,visibleInAddressBook,formattedAddress,town,firstName,line1,shippingAddress,line2,defaultAddress"/>
         </map>
     </property>
 </bean>

so you have to override in your custom extension/module dto-level-mappings-v2-spring.xml. file and add erpCustomerCode in Default.

Former Member
0 Kudos

yes thats was right thanks!

Answers (1)

Answers (1)

arvind-kumar_avinash
Active Contributor
0 Kudos

Hi @Prihan - Instead of directly adding erpCustomerCode attribute into AddressWsDTO and AddressData, please try adding it to the beans.xml. You can refer https://help.hybris.com/1808/hcd/8bbdfe9286691014a741829ebffd8512.html and https://help.hybris.com/1808/hcd/e571a0e6f7524d4ab62e29cc2b387aeb.html to validate if you are missing some step.

arvind-kumar_avinash
Active Contributor
0 Kudos

Hi - was it helpful?

Former Member
0 Kudos

yes it was ,, thank you.

arvind-kumar_avinash
Active Contributor
0 Kudos

You are most welcome. If you liked it, please upvote it to help others who may be looking for this topic in future.