Configure the RESTful JAX-RS JSON Date Serialization Format

By default, the JSON output for dates in Bloomreach Content is the number of milliseconds since the Unix epoch.

If you need to return dates in ISO-8601 format instead, you can configure the JAX-RS JSON serialization to use this format.

Bloomreach Content uses Jackson for serializing and deserializing JSON in JAX-RS resources. You can customize the date format by configuring the jaxrsRestJacksonObjectMapper bean in an overriding Spring assembly file. This file is typically located at /site/components/src/main/resources/META-INF/hst-assembly/overrides in your project.

To change the default JSON date serialization format, add the following bean definition to an overriding Spring XML assembly file (for example, META-INF/hst-assembly/overrides/jackson.xml):

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> <property name="targetObject" ref="jaxrsRestJacksonObjectMapper" /> <property name="targetMethod" value="setDateFormat"/> <property name="arguments"> <list> <bean class="java.text.SimpleDateFormat"> <constructor-arg value="yyyy-MM-dd'T'HH:mm:ssZZ"/> </bean> </list> </property> </bean>

This configuration sets the date format for JSON serialization to ISO-8601.

Share Feedback
Page: /build/rest-services/jax-rs-services/restful-jax-rs-json-date-serialization-format
Section: Build
Category *