Package org.molgenis.web.converter
Class GsonFactoryBean
- java.lang.Object
-
- org.molgenis.web.converter.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
AFactoryBeanfor creating a Google Gson 2.xGsoninstance.
-
-
Constructor Summary
Constructors Constructor Description GsonFactoryBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()com.google.gson.GsongetObject()Return the created Gson instance.Class<?>getObjectType()booleanisSingleton()voidregisterTypeAdapterFactory(com.google.gson.TypeAdapterFactory typeAdapterFactory)voidregisterTypeHierarchyAdapter(Class<?> clazz, Object typeAdapter)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.voidsetRegisterJavaTimeConverters(boolean registerJavaTimeConverters)Indicates if the java 8 date timeConvertersshould be registered with Gson.voidsetSerializeNulls(boolean serializeNulls)Whether to use theGsonBuilder.serializeNulls()option when writing JSON.
-
-
-
Method Detail
-
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
public void setDateFormatPattern(String dateFormatPattern)
Define the date/time format with aSimpleDateFormat-style pattern. This is a shortcut for setting up aGsonas follows:new GsonBuilder().setDateFormat(dateFormatPattern).create();
-
setRegisterJavaTimeConverters
public void setRegisterJavaTimeConverters(boolean registerJavaTimeConverters)
Indicates if the java 8 date timeConvertersshould 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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
getObject
public com.google.gson.Gson getObject()
Return the created Gson instance.- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<com.google.gson.Gson>
-
getObjectType
public Class<?> 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>
-
-