public class GsonFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>, org.springframework.beans.factory.InitializingBean
FactoryBean
for creating a Google Gson 2.x Gson
instance.Constructor and Description |
---|
GsonFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
com.google.gson.Gson |
getObject()
Return the created Gson instance.
|
Class<?> |
getObjectType() |
boolean |
isSingleton() |
void |
setBase64EncodeByteArrays(boolean base64EncodeByteArrays)
Whether to Base64-encode
byte[] properties when reading and
writing JSON. |
void |
setDateFormatPattern(String dateFormatPattern)
Define the date/time format with a
SimpleDateFormat -style pattern. |
void |
setDisableHtmlEscaping(boolean disableHtmlEscaping)
Whether to use the
GsonBuilder.disableHtmlEscaping() when writing
JSON. |
void |
setPrettyPrinting(boolean prettyPrinting)
Whether to use the
GsonBuilder.setPrettyPrinting() when writing
JSON. |
void |
setSerializeNulls(boolean serializeNulls)
Whether to use the
GsonBuilder.serializeNulls() option when writing
JSON. |
public void setBase64EncodeByteArrays(boolean base64EncodeByteArrays)
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.
public void setSerializeNulls(boolean serializeNulls)
GsonBuilder.serializeNulls()
option when writing
JSON. This is a shortcut for setting up a Gson
as follows:
new GsonBuilder().serializeNulls().create();
public void setPrettyPrinting(boolean prettyPrinting)
GsonBuilder.setPrettyPrinting()
when writing
JSON. This is a shortcut for setting up a Gson
as follows:
new GsonBuilder().setPrettyPrinting().create();
public void setDisableHtmlEscaping(boolean disableHtmlEscaping)
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();
public void setDateFormatPattern(String dateFormatPattern)
SimpleDateFormat
-style pattern.
This is a shortcut for setting up a Gson
as follows:
new GsonBuilder().setDateFormat(dateFormatPattern).create();
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
@Nullable public com.google.gson.Gson getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
public Class<?> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<com.google.gson.Gson>