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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
com.google.gson.Gson
Return the created Gson instance.Class<?>
boolean
void
setBase64EncodeByteArrays
(boolean base64EncodeByteArrays) Whether to Base64-encodebyte[]
properties when reading and writing JSON.void
setDateFormatPattern
(String dateFormatPattern) Define the date/time format with aSimpleDateFormat
-style pattern.void
setDisableHtmlEscaping
(boolean disableHtmlEscaping) Whether to use theGsonBuilder.disableHtmlEscaping()
when writing JSON.void
setPrettyPrinting
(boolean prettyPrinting) Whether to use theGsonBuilder.setPrettyPrinting()
when writing JSON.void
setSerializeNulls
(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 customTypeAdapter
will 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 aGson
as 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 aGson
as follows:new GsonBuilder().setPrettyPrinting().create();
-
setDisableHtmlEscaping
public void setDisableHtmlEscaping(boolean disableHtmlEscaping) Whether to use theGsonBuilder.disableHtmlEscaping()
when writing JSON. Set totrue
to disable HTML escaping in JSON. This is a shortcut for setting up aGson
as follows:new GsonBuilder().disableHtmlEscaping().create();
-
setDateFormatPattern
Define the date/time format with aSimpleDateFormat
-style pattern. This is a shortcut for setting up aGson
as follows:new GsonBuilder().setDateFormat(dateFormatPattern).create();
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
getObject
@Nullable public com.google.gson.Gson getObject()Return the created Gson instance.- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-
getObjectType
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-
isSingleton
public boolean isSingleton()- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-