Class JacksonHelper

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

    public class JacksonHelper
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_FILTER_NAME  
    • Constructor Summary

      Constructors 
      Constructor Description
      JacksonHelper()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()  
      <T> T construct​(java.io.Reader content, java.lang.Class<T> requiredType)
      Constructs the object based on the content.
      <T> java.util.List<T> constructList​(java.io.Reader content, java.lang.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
      void setModule​(com.fasterxml.jackson.databind.Module module)
      Sets the Jackson Module to be used.
      void withWriter​(java.io.OutputStream outStream, JacksonHelper.Writer writer)
      A callback so a JsonGenerator can be used inline but exception are handled here
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_FILTER_NAME

        public static final java.lang.String DEFAULT_FILTER_NAME
        See Also:
        Constant Field Values
    • 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 java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • withWriter

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

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

        public <T> java.util.List<T> constructList​(java.io.Reader content,
                                                   java.lang.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