Customize JSON Serialization of Domain-Specific POJO Models
Overview
Bloomreach Content includes several built-in Jackson Mixin Types (JacksonMixInAnnotations) to control how HST Content Beans are serialized to JSON.
You can extend this behavior by registering your own Jackson Mixin Types. This allows you to customize JSON serialization for your domain-specific POJO models without modifying their source code.
Register Custom Jackson Mixin Types
To register custom Jackson Mixin Types in your project, create an XML configuration file at the appropriate location for your Delivery API version:
Delivery API 1.0:
site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v10/
Delivery API 0.9 (brXM 14 only):
site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v09/
In this XML file, define the pageModelJacksonObjectMapperExtraMixins bean. Map each original target class to its corresponding Jackson mixin class. For 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" /> <!-- Additional mappings --> </map> </property> </bean>
In this configuration, each entry maps the fully qualified class name (FQCN) of your original POJO (for example, com.example.beans.OriginalBean) to the FQCN of the Jackson mixin class (com.example.mixins.OriginalBeanMixin). When the system serializes an OriginalBean instance, the ObjectMapper applies annotations from the specified mixin class. This approach allows you to customize serialization without altering the original class definition.