2025 Feb 12 6:40 PM - edited 2025 Feb 14 8:58 AM
Hi All,
OOTB DateAdapter class from webservicescommons has UTC time zone hardcoded. We need to make it system default time, but tried multiple ways to override the Adapter but nothing.
de.hybris.platform.webservicescommons.jaxb.adapters.DateAdapter
Can some suggest if there is any way we can override DateAdapter? There is one custom TimeZoneDateAdapter, we followed that process also to define our customer Date Adapter, but it didn't work.
Updated screenshots :
Solution for 2211.29:
Thanks.
Request clarification before answering.
Assuming that you have an OCC extension (e.g., customocc) generated from the yocc template and requiring commercewebservices, you can define a custom DateAdapter by following these steps:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="customJaxbContextFactory" />
<property name="targetMethod" value="setTypeAdapters" />
<property name="arguments">
<list value-type="java.lang.Class">
<value>your.package.customocc.jaxb.adapters.CustomDateAdapter</value>
<value>de.hybris.platform.webservicescommons.jaxb.adapters.StringMapAdapter</value>
<value>de.hybris.platform.webservicescommons.jaxb.adapters.XSSStringAdapter</value>
</list>
</property>
</bean>
I tried this on my local environment and successfully customized the output for Date attributes. The only drawback of this solution is that if SAP adds a new adapter to the customJaxbContextFactory bean, you will also need to add it to your bean definition.
To prevent this issue, we should remove DateAdapter from the list and add our CustomAdapter. However, I couldn't find an easy way to do this. I was able to achieve it using the following bean definitions, but it does not seem as simple and clear as the previous definition.
<bean id="customJaxbContextFactoryTypeAdaptersList" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="customJaxbContextFactory"/>
<property name="targetMethod" value="getTypeAdapters"/>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="customJaxbContextFactoryTypeAdaptersList"/>
<property name="targetMethod" value="remove"/>
<property name="arguments">
<list value-type="java.lang.Class">
<value>de.hybris.platform.webservicescommons.jaxb.adapters.DateAdapter</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="customJaxbContextFactoryTypeAdaptersList"/>
<property name="targetMethod" value="add"/>
<property name="arguments">
<list value-type="java.lang.Class">
<value>your.package.customocc.jaxb.adapters.CustomDateAdapter</value>
</list>
</property>
</bean>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="customJaxbContextFactory" />
<property name="targetMethod" value="setTypeAdapters" />
<property name="arguments">
<list>
<ref bean="customJaxbContextFactoryTypeAdaptersList"/>
</list>
</property>
</bean>
You can choose whichever approach you prefer—both work and are valid options.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the solution. For us (CCV2 2211.29) second option didn't work at all. First option worked but I needed to override - customJaxbContextFactory of Commerce Web services jaxb-coverters-spring.xml.
<alias name="defaultProjectNameJaxbContextFactory" alias="customJaxbContextFactory"/>
<bean id="defaultProjectNameJaxbContextFactory" parent="jaxbContextFactory">
<property name="metadataSourceFactory" ref="customMetadataSourceFactory" />
<property name="typeAdapters">
<list>
<value>com.ProjectName.jaxb.adaptors.ProjectNameDateAdapter</value>
<value>de.hybris.platform.webservicescommons.jaxb.adapters.StringMapAdapter</value>
<value>de.hybris.platform.webservicescommons.jaxb.adapters.XSSStringAdapter</value>
</list>
</property>
</bean>
User | Count |
---|---|
14 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.