Class GsonFactoryBean

  • All Implemented Interfaces:
    org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>, org.springframework.beans.factory.InitializingBean

    public class GsonFactoryBean
    extends Object
    implements org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>, org.springframework.beans.factory.InitializingBean
    A FactoryBean for creating a Google Gson 2.x Gson instance.
    • Constructor Detail

      • GsonFactoryBean

        public GsonFactoryBean()
    • Method Detail

      • setSerializeNulls

        public void setSerializeNulls​(boolean serializeNulls)
        Whether to use the GsonBuilder.serializeNulls() option when writing JSON. This is a shortcut for setting up a Gson as follows:

         new GsonBuilder().serializeNulls().create();
         
      • setPrettyPrinting

        public void setPrettyPrinting​(boolean prettyPrinting)
        Whether to use the GsonBuilder.setPrettyPrinting() when writing JSON. This is a shortcut for setting up a Gson as follows:

         new GsonBuilder().setPrettyPrinting().create();
         
      • setDisableHtmlEscaping

        public void setDisableHtmlEscaping​(boolean disableHtmlEscaping)
        Whether to use the GsonBuilder.disableHtmlEscaping() when writing JSON. Set to true to disable HTML escaping in JSON. This is a shortcut for setting up a Gson as follows:

         new GsonBuilder().disableHtmlEscaping().create();
         
      • setDateFormatPattern

        public void setDateFormatPattern​(String dateFormatPattern)
        Define the date/time format with a SimpleDateFormat-style pattern. This is a shortcut for setting up a Gson as follows:

         new GsonBuilder().setDateFormat(dateFormatPattern).create();
         
      • setRegisterJavaTimeConverters

        public void setRegisterJavaTimeConverters​(boolean registerJavaTimeConverters)
        Indicates if the java 8 date time Converters should be registered with Gson.

        This is equivalent to writing GsonBuilder builder = new GsonBuilder() Converters.registerInstant(builder); Converters.registerLocalDate(builder); builder.create(); The builders will be registered after the other type adapters and type adapter factories you set.

        Parameters:
        registerJavaTimeConverters - true if they should be registered
      • registerTypeAdapterFactory

        public void registerTypeAdapterFactory​(com.google.gson.TypeAdapterFactory typeAdapterFactory)
      • registerTypeHierarchyAdapter

        public void registerTypeHierarchyAdapter​(Class<?> clazz,
                                                 Object typeAdapter)
      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • getObject

        public com.google.gson.Gson getObject()
        Return the created Gson instance.
        Specified by:
        getObject in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
      • getObjectType

        public Class<?> getObjectType()
        Specified by:
        getObjectType in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
      • isSingleton

        public boolean isSingleton()
        Specified by:
        isSingleton in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>