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
-
Field Summary
Fields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcom.google.gson.GsonReturn the created Gson instance.Class<?>booleanvoidsetBase64EncodeByteArrays(boolean base64EncodeByteArrays) Whether to Base64-encodebyte[]properties when reading and writing JSON.voidsetDateFormatPattern(String dateFormatPattern) Define the date/time format with aSimpleDateFormat-style pattern.voidsetDisableHtmlEscaping(boolean disableHtmlEscaping) Whether to use theGsonBuilder.disableHtmlEscaping()when writing JSON.voidsetPrettyPrinting(boolean prettyPrinting) Whether to use theGsonBuilder.setPrettyPrinting()when writing JSON.voidsetSerializeNulls(boolean serializeNulls) Whether to use theGsonBuilder.serializeNulls()option when writing JSON.
-
Constructor Details
-
GsonFactoryBean
public GsonFactoryBean()
-
-
Method Details
-
setBase64EncodeByteArrays
public void setBase64EncodeByteArrays(boolean base64EncodeByteArrays) Whether to Base64-encodebyte[]properties when reading and writing JSON.When set to
true, a customTypeAdapterwill be registered viaGsonBuilder.registerTypeHierarchyAdapter(Class, Object)which serializes abyte[]property to and from a Base64-encoded String instead of a JSON array. -
setSerializeNulls
public void setSerializeNulls(boolean serializeNulls) Whether to use theGsonBuilder.serializeNulls()option when writing JSON. This is a shortcut for setting up aGsonas follows:new GsonBuilder().serializeNulls().create();
-
setPrettyPrinting
public void setPrettyPrinting(boolean prettyPrinting) Whether to use theGsonBuilder.setPrettyPrinting()when writing JSON. This is a shortcut for setting up aGsonas follows:new GsonBuilder().setPrettyPrinting().create();
-
setDisableHtmlEscaping
public void setDisableHtmlEscaping(boolean disableHtmlEscaping) Whether to use theGsonBuilder.disableHtmlEscaping()when writing JSON. Set totrueto disable HTML escaping in JSON. This is a shortcut for setting up aGsonas follows:new GsonBuilder().disableHtmlEscaping().create();
-
setDateFormatPattern
Define the date/time format with aSimpleDateFormat-style pattern. This is a shortcut for setting up aGsonas follows:new GsonBuilder().setDateFormat(dateFormatPattern).create();
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
getObject
@Nullable public com.google.gson.Gson getObject()Return the created Gson instance.- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-
getObjectType
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-