Jackson ObjectMapper Config in Hippo CRISP

October 12th 2018 Hippo CMS Java Spring

The recommended way for integrating external services in Hippo CMS is the CRISP API. The official documentation provides detailed enough instructions for installing, configuring and using it. However, when I needed to customize the default Jackson ObjectMapper, it wasn't all that obvious how I could do it.

The REST service I had to call was returning a date value:

[ {
    "name": "John",
    "surname": "Doe",
    "birthDate": "1980-05-01"
} ]

In my Java code I wanted to deserialize it into a LocalDate:

public class Person {

    // ...
    private LocalDate birthDate;

    // ...

    public LocalDate getBirthDate() {
        return birthDate;

    public void setBirthDate(LocalDate birthDate) {
        this.birthDate = birthDate;

I configured a matching CRISP resource based on the example from the documentation, only removing the resourceLinkResolver.

The code for calling the service and deserializing the result is pretty straightforward:

ResourceServiceBroker broker =
Resource resourceRoot = broker.resolve(DEMO_RESOURCE, "/persons");
ResourceCollection resourceCollection = resourceRoot.getChildren();
ResourceBeanMapper resourceBeanMapper = broker.getResourceBeanMapper(DEMO_RESOURCE);
Collection<Person> persons =
    resourceBeanMapper.mapCollection(resourceCollection, Person.class);

Unfortunately, the deserialization failed:

java.lang.IllegalArgumentException: Can not construct instance of java.time.LocalDate: no String-argument constructor/factory method to deserialize from String value ('1980-05-01')

To make it work, I would need to register the JavaTimeModule. I started by adding the dependency to the site module pom.xml:


And the root pom.xml:


To configure the ObjectMapper, I had to modify the CRISP resource configuration XML. The SimpleJacksonRestTemplateResourceResolver has an objectMapper property which can be used to provide a different ObjectMapper:

<bean parent="abstractCrispSimpleJacksonRestTemplateResourceResolver"

  <!-- ... -->
  <property name="objectMapper">
    <bean id="test"
      <property name="targetClass"
                value="com.damirscorner.blog.samples.utils.ObjectMapperFactory" />
      <property name="targetMethod" value="getObjectMapper" />

To make my work easier, I invoked a factory method inside which I configure the ObjectMapper correctly:

public class ObjectMapperFactory {

    private static ObjectMapper mapper;

    public static ObjectMapper getObjectMapper() {
        if (mapper == null)
            mapper = new ObjectMapper();
            mapper.registerModule(new JavaTimeModule());
        return mapper;

With all that set up, the ResourceBeanMapper now used my custom ObjectMapper for deserialization which resolved my issue with the LocalDate.

Get notified when a new blog post is published (usually every Friday):

If you're looking for online one-on-one mentorship on a related topic, you can find me on Codementor.
If you need a team of experienced software engineers to help you with a project, contact us at Razum.
Creative Commons License