Customize JSON Serialization of Domain-Specific POJO Models

Introduction

Many built-in Jackson Mixin Types (JacksonMixInAnnotations) are included to customize the default JSON serialization behavior for the HST Content Beans.

You can also add your own Jackson Mixin Types (JacksonMixInAnnotations) in order to customize the serialization for your domain-specific POJO models.

Add Custom Jackson Mixin Types

In order to add any custom Jackson Mixin Types (JacksonMixInAnnotations) in your project, add an XML file at one of the following locations (depending on the Delivery API version) in your project:

Delivery API 1.0:

site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v10/

Delivery API 0.9 (Bloomreach Experience Manager 14 only):

site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v09/

Inside the XML file, configure the bean named pageModelJacksonObjectMapperExtraMixins with your custom mixin types like the following example:

  <bean id="pageModelJacksonObjectMapperExtraMixins"
        class="org.springframework.beans.factory.config.MapFactoryBean">
    <property name="sourceMap">
      <map key-type="java.lang.Class" value-type="java.lang.Class">
        <entry key="com.example.beans.OriginalBean" value="com.example.mixins.OriginalBeanMixin" />
        <!-- SNIP -->
      </map>
    </property>
  </bean>

The above example adds a pair of the original target class' FQCN (e.g, com.example.beans.OriginalBean) and the new Jackson mixin class' FQCN (com.example.mixins.OriginalBeanMixin). So, whenever serializing an OriginalBean model object, the underlying ObjectMapper will combine the annotations defined in the OriginalBeanMixin class, resulting in custom serializations without changing the original target class.

 

 

 

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?