Custom Jackson Module for Delivery API

Hi,
we are working on implementing headless using the delivery API. We need to register the JodaModule in the Jackson ObjectMapper because JodaTime is still used.
In the documentation on Customize JSON Serialization of Domain-Specific POJO Models - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS it states that some Spring configuration is needed to have a Custom Jackson ObjectMapper. On that ObjectMapper we can register the JodaModule. So far this is not working. Is this documenation correct? Are there other ways to register a Module for jackson?

We are on version 14.latest and using PMA version 1.0.
Thanks!

Do you have any errors in the logs?

Hi Jasper,

The error in the console is:

org.hippoecm.hst.core.container.ContainerException: org.hippoecm.hst.core.container.ContainerException: Joda date/time type org.joda.time.DateTime not supported by default: add Module “com.fasterxml.jackson.datatype:jackson-datatype-joda” to enable handling (through reference chain: org.hippoecm.hst.pagemodelapi.v10.core.container.AggregatedPageModel[“page”]->org.hippoecm.hst.pagemodelapi.v10.core.container.PageModelSerializer$DecoratedPageModelEntityWrapper[“data”]->…

I added the following Spring config file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">

  <bean id="jodaModule" class="com.fasterxml.jackson.datatype.joda.JodaModule"/>

  <bean id="pageModelAggregationObjectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>

  <bean id="methodInvokerBeanDinges" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject" ref="pageModelAggregationObjectMapper"/>
    <property name="targetMethod" value="registerModule"/>
    <property name="arguments" ref="jodaModule"/>
  </bean>
</beans>

Is the file in correct location? It must be in site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v09/

we have no site/components module. Just the site module (it’s an old project).
Since we use delivery v1.0 I have placed the file in site/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v10/

Hi,

I’ve done some checking. It seems that page is wrong as of:
https://issues.onehippo.com/browse/HSTTWO-4734

I guess someone forgot to update the documentation. I have reported this.

There is now a bean

  <bean id="pageModelObjectMapperFactory" class="org.hippoecm.hst.pagemodelapi.common.content.beans.PageModelObjectMapperFactory">
  </bean>

You could extend org.hippoecm.hst.pagemodelapi.common.content.beans.PageModelObjectMapperFactory and in there create your own object mapper. Override org.hippoecm.hst.pagemodelapi.common.content.beans.PageModelObjectMapperFactory#createPageModelObjectMapper in your new class.

    public ObjectMapper createPageModelObjectMapper() {
        final ObjectMapper objectMapper = new CustomObjectMapper();
        objectMapper.setAnnotationIntrospector(new PageModelAnnotationIntrospector());
        return objectMapper;
    }

something like that. I think that should work, but I am not 100% sure on that.

I have been informed that the proposed will likely work, but it isn’t a supported extension point. This means that future updates may break it without warning or deprecation.

No promises that it actually will work though.

Another possible solution would be to use jackson mixin annotation:

@JsonSerialize(converter= MyConverter.class)