Customize JSON Serialization of Domain-Specific POJO Models


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 to site/components/src/main/resources/META-INF/hst-assembly/overrides/addon/org/hippoecm/hst/pagemodelapi/v09/, and configure the bean named pageModelJacksonObjectMapperExtraMixins with your custom mixin types like the following example:

  <bean id="pageModelJacksonObjectMapperExtraMixins"
    <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 -->

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?

    We rely on cookies

    to optimize our communication and to enhance your customer experience. By clicking on the Accept and Close button, you agree to the collection of cookies. You can also adjust your preferences by clicking on Manage Preferences. For more information please see our Privacy policy.

    Manage cookies
    Accept & close

    Cookies preferences

    Accept & close