I have an object in my data class and I want only a specific attribute of this object in the WsDTO class.
Declaration of custom B2BUnitData
<bean class="de.hybris.platform.b2bcommercefacades.company.data.B2BUnitData">
<property name="PointOfServiceData"
type="de.hybris.platform.commercefacades.storelocator.data.PointOfServiceData"/>
</bean>
Declaration of B2bUnitWsDTO
<bean class="de.hybris.platform.b2boccaddon.dto.b2bunit.B2bUnitWsDTO">
<property name="PointOfServiceData" type="PointOfServiceWsDTO" />
</bean>
file : dto-level-mappings-v2-spring.xml
<bean parent="fieldSetLevelMapping" id="b2bunitWsDTOFieldSetLevelMapping">
<property name="dtoClass"
value="de.hybris.platform.b2boccaddon.dto.pricerow.B2bUnitWsDTO"/>
<property name="levelMapping">
<map>
<entry key="FULL" value="PointOfServiceData" />
</map>
</property>
</bean>
this implementation give me all the object pointOfService but I only want the UID attribute in the B2bUnitWsDTO
The only solution I know, will be to create a PointOfServiceUID attribute in the data and map it directly in the b2bunitWsDTOFieldSetLevelMapping bean.
I would know if it's possible to map in the dto-level-mappings-v2-spring.xml only one attribute of my object :
Exemple :
Or if it exist some solution to do that
As you already mentioned, you could change the dto-level-mappings-v2-spring.xml
so that for all levels (BASIC
, DEFAULT
, FULL
) only the uid is returned.
<bean parent="fieldSetLevelMapping" id="b2bunitWsDTOFieldSetLevelMapping">
<property name="dtoClass"
value="de.hybris.platform.b2boccaddon.dto.pricerow.B2bUnitWsDTO"/>
<property name="levelMapping">
<map>
<entry key="BASIC" value="PointOfServiceData(uid)" />
<entry key="DEFAULT" value="PointOfServiceData(uid)" />
<entry key="FULL" value="PointOfServiceData(uid)" />
</map>
</property>
</bean>
Beware, the fieldSetLevelMapping
beans only define how your response looks like!
If you want to change how a B2BUnitData
is mapped to a B2bUnitWsDTO
, you have to define a custom field mapper (you can find examples in dto-mappings-v2-spring.xml
)
Assuming your B2bUnitWsDTO
now only has pointOfServiceUID
as property, this may look like this (disclaimer: you need to test this):
<bean id="b2bUnitFieldMapper" parent="fieldMapper">
<property name="sourceClass"
value="de.hybris.platform.b2bcommercefacades.company.data.B2BUnitData"/>
<property name="destClass"
value="com.customer.some.package.B2bUnitWsDTO"/>
<property name="fieldMapping">
<map>
<entry key="PointOfServiceData.uid" value="pointOfServiceUID"/>
</map>
</property>
</bean>
Here is a good documentation entry point regarding Field Mappings and Field Level Definitions: https://help.hybris.com/1808/hcd/8c404c5886691014a48c88f4a49f9bf3.html