Class GsonFactoryBean

java.lang.Object
org.springframework.http.converter.json.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.
Since:
4.1
Author:
Roy Clarkson, Juergen Hoeller
  • Constructor Details

    • GsonFactoryBean

      public GsonFactoryBean()
  • Method Details

    • setBase64EncodeByteArrays

      public void setBase64EncodeByteArrays(boolean base64EncodeByteArrays)
      Whether to Base64-encode byte[] properties when reading and writing JSON.

      When set to true, a custom TypeAdapter will be registered via GsonBuilder.registerTypeHierarchyAdapter(Class, Object) which serializes a byte[] property to and from a Base64-encoded String instead of a JSON array.

      See Also:
    • 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();
       
    • afterPropertiesSet

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

      @Nullable 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>