Configure the RESTful JAX-RS JSON Date Serialization Format - BloomReach Experience - Open Source CMS

Configure the RESTful JAX-RS JSON Date Serialization Format

The default JSON output for dates is the number of millseconds since the Epoch.

In some cases however it might be more useful to use and return an ISO-8601 formatted date.

HST-2 JAX-RS uses Jackson to serialize and deserialize objects to/from JSON, and through the Spring Framework jaxrsRestJacksonObjectMapper bean configuration you can set a custom date format for its serializer configuration in an overriding Spring assembly file. This overriding Spring assembly file is normally located in your project at /site/components/src/main/resources/META-INF/hst-assembly/overrides.

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

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