Class JacksonHelper

  • All Implemented Interfaces:
    org.springframework.beans.factory.InitializingBean

    public class JacksonHelper
    extends Object
    implements org.springframework.beans.factory.InitializingBean
    Helper Class for outputting Jackson content, makes use of the RestJsonModule (main Jackson config). Default settings : Date format is ISO8601, only serializes non-empty / non-null values.
    Author:
    Gethin James
    • Constructor Detail

      • JacksonHelper

        public JacksonHelper()
    • Method Detail

      • setModule

        public void setModule​(com.fasterxml.jackson.databind.Module module)
        Sets the Jackson Module to be used.
        Parameters:
        module - Module
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        Exception
      • withWriter

        public void withWriter​(OutputStream outStream,
                               JacksonHelper.Writer writer)
                        throws IOException
        A callback so a JsonGenerator can be used inline but exception are handled here
        Parameters:
        outStream - OutputStream
        writer - The writer interface
        Throws:
        IOException
      • construct

        public <T> T construct​(Reader content,
                               Class<T> requiredType)
        Constructs the object based on the content.
        Parameters:
        content - Reader
        Returns:
        T
      • constructList

        public <T> List<T> constructList​(Reader content,
                                         Class<T> requiredType)
        Constructs the object based on the content as a List, the JSON can be an array or just a single value without the [] symbols
        Parameters:
        content - Reader
        Returns:
        A collection of the specified type